当前位置: 首页>>代码示例>>C#>>正文


C# Syntax.FieldDeclarationSyntax类代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.FieldDeclarationSyntax的典型用法代码示例。如果您正苦于以下问题:C# FieldDeclarationSyntax类的具体用法?C# FieldDeclarationSyntax怎么用?C# FieldDeclarationSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FieldDeclarationSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了FieldDeclarationSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreatePropertiesField

        /// <summary>
        /// Creates a field that holds <see cref="QueryTypeProperties{T}"/> for the module.
        /// </summary>
        protected FieldDeclarationSyntax CreatePropertiesField(
            Module module, string resultClassName, FieldDeclarationSyntax propsField, SortType? sortType)
        {
            var queryTypePropertiesType = SyntaxEx.GenericName("QueryTypeProperties", resultClassName);

            var propertiesInitializer = SyntaxEx.ObjectCreation(
                queryTypePropertiesType,
                SyntaxEx.Literal(module.Name),
                SyntaxEx.Literal(module.Prefix),
                module.QueryType == null
                    ? (ExpressionSyntax)SyntaxEx.NullLiteral()
                    : SyntaxEx.MemberAccess("QueryType", module.QueryType.ToString()),
                sortType == null
                    ? (ExpressionSyntax)SyntaxEx.NullLiteral()
                    : SyntaxEx.MemberAccess("SortType", sortType.ToString()),
                CreateTupleListExpression(GetBaseParameters(module)),
                propsField == null ? (ExpressionSyntax)SyntaxEx.NullLiteral() : (NamedNode)propsField,
                resultClassName == "object"
                    ? (ExpressionSyntax)SyntaxEx.LambdaExpression("_", SyntaxEx.NullLiteral())
                    : SyntaxEx.MemberAccess(resultClassName, "Parse"));

            return SyntaxEx.FieldDeclaration(
                new[] { SyntaxKind.PrivateKeyword, SyntaxKind.StaticKeyword, SyntaxKind.ReadOnlyKeyword },
                queryTypePropertiesType, ClassNameBase + "Properties", propertiesInitializer);
        }
开发者ID:joshbtn,项目名称:LINQ-to-Wiki,代码行数:28,代码来源:ModuleGeneratorBase.cs

示例2: GetFieldName

 public static string GetFieldName(FieldDeclarationSyntax field)
 {
     var variable = field.Declaration.Variables.FirstOrDefault(); //.DescendantNodes().Where(e => e.IsKind(SyntaxKind.IdentifierToken)).Last().Span.ToString();
     if (variable == null)
         return "";
     return variable.Identifier.ToString();
 }
开发者ID:OsvaldoJ,项目名称:orchardizer,代码行数:7,代码来源:RoslynExtensions.cs

示例3: VisitFieldDeclaration

            public override SyntaxNode VisitFieldDeclaration(FieldDeclarationSyntax node)
            {
                bool isInstance;
                if (NeedsRewrite(node, out isInstance))
                {
                    var list = new List<VariableDeclaratorSyntax>(node.Declaration.Variables.Count);
                    foreach (var v in node.Declaration.Variables)
                    {
                        if (IsGoodPrivateFieldName(v.Identifier.Text, isInstance))
                        {
                            list.Add(v);
                        }
                        else
                        {
                            list.Add(v.WithAdditionalAnnotations(s_markerAnnotation));
                            _count++;
                        }
                    }

                    var declaration = node.Declaration.WithVariables(SyntaxFactory.SeparatedList(list));
                    node = node.WithDeclaration(declaration);

                    return node;
                }

                return node;
            }
开发者ID:chuck-mitchell,项目名称:codeformatter,代码行数:27,代码来源:PrivateFieldNamingRule.CSharp.cs

示例4: FieldDeclarationTranslation

 public FieldDeclarationTranslation(FieldDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
 {
     Declaration = syntax.Declaration.Get<VariableDeclarationTranslation>(this);
     Declaration.ExcludeVar = true;
     Modifiers = syntax.Modifiers.Get(this);
     Modifiers.ConstantToStatic = true;                     
 }
开发者ID:asthomas,项目名称:TypescriptSyntaxPaste,代码行数:7,代码来源:FieldDeclarationTranslation.cs

示例5: VisitFieldDeclaration

 public override SyntaxNode VisitFieldDeclaration(FieldDeclarationSyntax node)
 {
     if (_fieldsToRemove.Contains(node.GetText().ToString()))
     {
         return null;
     }
     return base.VisitFieldDeclaration(node);
 }
开发者ID:CNinnovation,项目名称:TechConference2016,代码行数:8,代码来源:RemoveBackingFieldRewriter.cs

示例6: AddReadonlyModifier

        private async Task<Document> AddReadonlyModifier(Document document, SyntaxNode root, FieldDeclarationSyntax fieldDeclaration, CancellationToken cancellationToken)
        {
            var docEditor = await DocumentEditor.CreateAsync(document, cancellationToken).ConfigureAwait(false);
            var modifiers = docEditor.Generator.GetModifiers(fieldDeclaration);
            docEditor.SetModifiers(fieldDeclaration, modifiers + DeclarationModifiers.ReadOnly);

            return docEditor.GetChangedDocument();
        }
开发者ID:michaelcfanning,项目名称:codeformatter,代码行数:8,代码来源:UnwrittenWritableFieldFixer.cs

示例7: VisitFieldDeclaration

        public override void VisitFieldDeclaration(FieldDeclarationSyntax node)
        {
            string visibility = GetVisibilityModifier(node.Modifiers);

            foreach (var identifier in node.Declaration.Variables)
            {
                Emit(string.Format("{0} {1}: {2};", visibility, identifier.GetText(), GetMappedType(node.Declaration.Type)));
            }
        }
开发者ID:benlaan,项目名称:cs2ts,代码行数:9,代码来源:Transpiler.cs

示例8: MakeSingleFieldReadonly

 private static SyntaxNode MakeSingleFieldReadonly(SyntaxNode root, FieldDeclarationSyntax fieldDeclaration)
 {
     var newFieldDeclaration = fieldDeclaration.AddModifiers(SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword))
         .WithTrailingTrivia(fieldDeclaration.GetTrailingTrivia())
         .WithLeadingTrivia(fieldDeclaration.GetLeadingTrivia())
         .WithAdditionalAnnotations(Formatter.Annotation);
     var newRoot = root.ReplaceNode(fieldDeclaration, newFieldDeclaration);
     return newRoot;
 }
开发者ID:nagyistoce,项目名称:code-cracker,代码行数:9,代码来源:ReadonlyFieldCodeFixProvider.cs

示例9: VisitFieldDeclaration

 public override void VisitFieldDeclaration(FieldDeclarationSyntax node)
 {
     base.VisitFieldDeclaration(node);
     foreach (var variable in node.Declaration.Variables)
     {
         var test = variable.Identifier;
         DefinedOutside.Add(variable.Identifier.ToString(), variable.ToFullString());
     }
     var t = DefinedOutside;
 }
开发者ID:AmadeusW,项目名称:SnippetVS,代码行数:10,代码来源:DiscoveryWalker.cs

示例10: VisitFieldDeclaration

        public override void VisitFieldDeclaration(FieldDeclarationSyntax node)
        {
            string type = node.Declaration.Type.ToString();
            foreach (Variable var in node.Declaration.Variables.Select(val => new Variable() { Name = val.Identifier.ToString(), Type = type }))
            {
                this.Variables.Add(var);
            }

            base.VisitFieldDeclaration(node);
        }
开发者ID:chemix-lunacy,项目名称:Skyling,代码行数:10,代码来源:VariableWalker.cs

示例11: Go

 public static void Go(OutputWriter writer, FieldDeclarationSyntax field)
 {
     foreach (var declaration in field.Declaration.Variables)
     {
       
         //TODO: Add support for threadstatic
         Go(writer, field, field.Modifiers,
             WriteIdentifierName.TransformIdentifier(declaration.Identifier.Text), field.Declaration.Type,
             declaration.Initializer,field.IsThreadStatic());
     }
 }
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:11,代码来源:WriteField.cs

示例12: CaptureCandidateFields

        private static void CaptureCandidateFields(FieldDeclarationSyntax field, SemanticModel semanticModel, List<FieldCandidate> candidateFields)
        {

            if (!CanBecameReadOnlyField(field)) return;
            var variables = field.Declaration.Variables;
            var currentAnalysisCandidateFields = variables.Select(s => new FieldCandidate { Variable = s, FieldSymbol = semanticModel.GetDeclaredSymbol(s) as IFieldSymbol })
                .Where(p => p.FieldSymbol != null && p.FieldSymbol.ContainingType != null);

            if (!currentAnalysisCandidateFields.Any()) return;
            candidateFields.AddRange(currentAnalysisCandidateFields);
        }
开发者ID:haroldhues,项目名称:code-cracker,代码行数:11,代码来源:NoPrivateReadonlyFieldAnalyzer.cs

示例13: MakeReadOnlyAsync

        private async Task<Document> MakeReadOnlyAsync(Document document, FieldDeclarationSyntax fieldDecl, CancellationToken cancellationToken)
        {
            var roKeyword = SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword);
            var roFieldDecl = fieldDecl.AddModifiers(roKeyword);

            var root = await document.GetSyntaxRootAsync(cancellationToken);
            var newRoot = root.ReplaceNode(fieldDecl, roFieldDecl);

            var newDocument = document.WithSyntaxRoot(newRoot);
            return newDocument;
        }
开发者ID:itowlson,项目名称:torment-roslyn,代码行数:11,代码来源:CodeFixProvider.cs

示例14: MakeMultipleFieldsReadonly

 private static SyntaxNode MakeMultipleFieldsReadonly(SyntaxNode root, FieldDeclarationSyntax fieldDeclaration, VariableDeclaratorSyntax variableToMakeReadonly)
 {
     var newDeclaration = fieldDeclaration.Declaration.RemoveNode(variableToMakeReadonly, SyntaxRemoveOptions.KeepEndOfLine);
     var newFieldDeclaration = fieldDeclaration.WithDeclaration(newDeclaration);
     var newReadonlyFieldDeclaration = fieldDeclaration.WithDeclaration(SyntaxFactory.VariableDeclaration(fieldDeclaration.Declaration.Type, SyntaxFactory.SeparatedList(new[] { variableToMakeReadonly })))
         .WithoutLeadingTrivia()
         .WithTrailingTrivia(SyntaxFactory.ParseTrailingTrivia("\n"))
         .AddModifiers(SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword))
         .WithAdditionalAnnotations(Formatter.Annotation);
     var newRoot = root.ReplaceNode(fieldDeclaration, new[] { newFieldDeclaration, newReadonlyFieldDeclaration });
     return newRoot;
 }
开发者ID:nagyistoce,项目名称:code-cracker,代码行数:12,代码来源:ReadonlyFieldCodeFixProvider.cs

示例15: VisitFieldDeclaration

        public override SyntaxNode VisitFieldDeclaration(FieldDeclarationSyntax field)
        {
            // Retrieve the symbol for the field's variable
            if (field.Declaration.Variables.Count == 1)
            {
                if (object.Equals(semanticModel.GetDeclaredSymbol(field.Declaration.Variables.First()), backingField))
                {
                    return null;
                }
            }

            return field;
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:13,代码来源:PropertyRewriter.cs


注:本文中的Microsoft.CodeAnalysis.CSharp.Syntax.FieldDeclarationSyntax类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。