• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Syntax.FieldDeclarationSyntax类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: CheckForDiagnostics

    private static void CheckForDiagnostics(SyntaxNodeAnalysisContext context, FieldDeclarationSyntax fieldNode, IFieldSymbol fieldSymbol)
    {
      var isStatic = fieldSymbol.IsStatic;
      var isPublic = fieldSymbol.DeclaredAccessibility.HasFlag(Accessibility.Public);
      var isReadOnly = fieldSymbol.IsReadOnly;

      if (!isStatic || !isPublic || !isReadOnly)
      {
        context.ReportDiagnostic(Diagnostic.Create(
          EvaluateManagedBackingFieldsAnalayzer.mustBePublicStaticAndReadonlyRule,
          fieldNode.GetLocation()));
      }
    }
开发者ID:ronnymgm,项目名称:csla-light,代码行数:13,代码来源:EvaluateManagedBackingFieldsAnalayzer.cs


示例17: MakePrivateDeclarationAsync

        private async Task<Document> MakePrivateDeclarationAsync(Document document, FieldDeclarationSyntax declaration, CancellationToken c)
        {
            var accessToken = declaration.ChildTokens()
                .SingleOrDefault(token => token.Kind() == SyntaxKind.PublicKeyword);

            var privateAccessToken = SyntaxFactory.Token(SyntaxKind.PrivateKeyword);

            var root = await document.GetSyntaxRootAsync(c);
            var newRoot = root.ReplaceToken(accessToken, privateAccessToken);

            return document.WithSyntaxRoot(newRoot);

        }
开发者ID:Winsto,项目名称:MVA-Roslyn,代码行数:13,代码来源:CodeFixProvider.cs


示例18: MakePrivateAsync

        private async Task<Document> MakePrivateAsync(Document document, FieldDeclarationSyntax fieldDeclaration, CancellationToken cancellationToken) {
            SyntaxToken privateSyntaxToken = CreatePrivateSyntaxToken(fieldDeclaration);
            IEnumerable<SyntaxToken> newFieldModifiers = new[] { privateSyntaxToken }.Union(
                fieldDeclaration.Modifiers.Where(modifier =>
                        modifier.Kind() != SyntaxKind.InternalKeyword && modifier.Kind() != SyntaxKind.PublicKeyword)
                        .Select(modifier => modifier.WithLeadingTrivia()));

            FieldDeclarationSyntax newfieldDeclaration = fieldDeclaration.Update(fieldDeclaration.AttributeLists,
                        new SyntaxTokenList().AddRange(newFieldModifiers),
                        fieldDeclaration.Declaration.WithoutTrivia(),
                        fieldDeclaration.SemicolonToken)
                        .WithLeadingTrivia(fieldDeclaration.GetLeadingTrivia())
                        .WithTrailingTrivia(fieldDeclaration.GetTrailingTrivia());

            return await this.ReplaceNodeInDocumentAsync(document, cancellationToken, fieldDeclaration, newfieldDeclaration);
        }
开发者ID:vuder,项目名称:CodingStandardCodeAnalyzers,代码行数:16,代码来源:FieldAccessCodeAnalyzerCodeFixProvider.cs


示例19: LastField

        private static MemberDeclarationSyntax LastField(
            SyntaxList<MemberDeclarationSyntax> members,
            FieldDeclarationSyntax fieldDeclaration)
        {
            var lastConst = members.AsEnumerable()
                              .OfType<FieldDeclarationSyntax>()
                              .Where(f => f.Modifiers.Any(SyntaxKind.ConstKeyword)).LastOrDefault();

            // Place a const after the last existing const.
            if (fieldDeclaration.Modifiers.Any(SyntaxKind.ConstKeyword))
            {
                return lastConst;
            }

            // Place a field after the last field, or after the last const.
            return LastField(members) ?? lastConst;
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:17,代码来源:FieldGenerator.cs


示例20: NeedsRewrite

            private static bool NeedsRewrite(FieldDeclarationSyntax fieldSyntax, out bool isInstance)
            {
                if (!IsPrivateField(fieldSyntax, out isInstance))
                {
                    return false;
                }

                foreach (var v in fieldSyntax.Declaration.Variables)
                {
                    if (!IsGoodPrivateFieldName(v.Identifier.ValueText, isInstance))
                    {
                        return true;
                    }
                }

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Syntax.ForEachStatementSyntax类代码示例发布时间:2022-05-26
下一篇:
C# Syntax.ExpressionStatementSyntax类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap