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


C# FieldDeclarationSyntax.WithDeclaration方法代码示例

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


在下文中一共展示了FieldDeclarationSyntax.WithDeclaration方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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

示例2: 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

示例3: HandleFieldDeclaration

        private static SyntaxNode HandleFieldDeclaration(FieldDeclarationSyntax node)
        {
            VariableDeclarationSyntax declaration = node.Declaration;
            if (declaration == null || declaration.IsMissing)
            {
                return null;
            }

            SyntaxTokenList modifiers = DeclarationModifiersHelper.AddModifier(node.Modifiers, ref declaration, SyntaxKind.PrivateKeyword);
            return node
                .WithDeclaration(declaration)
                .WithModifiers(modifiers)
                .WithoutFormatting();
        }
开发者ID:Romanx,项目名称:StyleCopAnalyzers,代码行数:14,代码来源:SA1400CodeFixProvider.cs

示例4: VisitFieldDeclaration

        public override SyntaxNode VisitFieldDeclaration(FieldDeclarationSyntax node)
        {
            node = node.WithDeclaration((VariableDeclarationSyntax)VisitVariableDeclaration(node.Declaration));
            if (node.Declaration.Variables.Count == 1)
            {
                string typeName = node.Declaration.Type.ToString();
                switch (typeName)
                {
                    case "typedef":
                    {
                        Debug.Assert(pending_ == null);
                        pending_ = new ResolveTypedef(node, ctx_);
                        return null;
                    }

                    case "property":
                    {
                        var variable    = node.Declaration.Variables[0];
                        var initializer = variable.Initializer;
                        if (initializer != null)
                        {
                            var propType = Compiler.ConstantType(initializer.Value);
                            var result   = Compiler.Property(propType, variable.Identifier);
                            return result;
                        }
                        return node;
                    }
                }

                string variableName = node.Declaration.Variables[0].Identifier.ToString();
                switch (variableName)
                {
                    case "function":
                    case "method":
                    {
                        //when functions are declared with types the parser generates
                        //a subsquent erroneous method declaration
                        Debug.Assert(pending_ == null);
                        pending_ = new ResolveTypedFunction(node, ctx_, variableName == "method");
                        return null;
                    }
                    case "property":
                    {
                        //when functions are declared with types the parser generates
                        //a subsquent erroneous method declaration
                        Debug.Assert(pending_ == null);

                        var result = Compiler.Property(node.Declaration.Type);
                        pending_ = new ResolveProperty(result);
                        return null;
                    }
                }

            }
            return node;
        }
开发者ID:mpmedia,项目名称:Excess,代码行数:56,代码来源:Compiler.cs

示例5: RemoveField

 private static SyntaxNode RemoveField(SyntaxNode root, VariableDeclaratorSyntax variableDeclarator, FieldDeclarationSyntax fieldDeclaration)
 {
     var currentField = root.GetCurrentNode(fieldDeclaration);
     var multipleVariableDeclaration = fieldDeclaration.Declaration.Variables.Count > 1;
     root = multipleVariableDeclaration
         ? root.ReplaceNode(currentField, fieldDeclaration
             .WithDeclaration(fieldDeclaration.Declaration.RemoveNode(variableDeclarator, SyntaxRemoveOptions.KeepNoTrivia)))
         : root.RemoveNode(currentField, SyntaxRemoveOptions.KeepNoTrivia);
     return root;
 }
开发者ID:julianosaless,项目名称:code-cracker,代码行数:10,代码来源:SwitchToAutoPropCodeFixProvider.cs


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