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


C# SyntaxNode.ReplaceNodes方法代码示例

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


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

示例1: GetUpdatedDocumentAsync

 internal override Task<Document> GetUpdatedDocumentAsync(Document document, SemanticModel model, SyntaxNode root, SyntaxNode nodeToFix, Diagnostic diagnostic, CancellationToken cancellationToken)
 {
     var classSymbol = (INamedTypeSymbol)model.GetDeclaredSymbol(nodeToFix, cancellationToken);
     var instanceConstructors = classSymbol.InstanceConstructors.Where(t => t.DeclaredAccessibility == Accessibility.Public).Select(t => GetDeclaration(t)).Where(d => d != null).ToList();
     var generator = SyntaxGenerator.GetGenerator(document);
     var newRoot = root.ReplaceNodes(instanceConstructors, (original, rewritten) => generator.WithAccessibility(original, Accessibility.Protected));
     return Task.FromResult(document.WithSyntaxRoot(newRoot));
 }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:8,代码来源:CA1012CodeFixProvider.cs

示例2: GetUpdatedDocumentAsync

        internal override Task<Document> GetUpdatedDocumentAsync(Document document, SemanticModel model, SyntaxNode root, SyntaxNode nodeToFix, string diagnosticId, CancellationToken cancellationToken)
        {
            var classSymbol = (INamedTypeSymbol)model.GetDeclaredSymbol(nodeToFix);
            var instanceConstructors = classSymbol.InstanceConstructors.Where(t => t.DeclaredAccessibility == Accessibility.Public).Select(t => t.DeclaringSyntaxReferences[0].GetSyntax());
            var workspace = document.Project.Solution.Workspace;
            Func<SyntaxNode, SyntaxNode, SyntaxNode> replacementForNodes = (constructorNode, dummy) =>
                {
                    var newSyntax = CodeGenerator.UpdateDeclarationAccessibility(constructorNode, workspace, Accessibility.Protected, cancellationToken: cancellationToken).WithAdditionalAnnotations(Formatter.Annotation);
                    return newSyntax;
                };

            return Task.FromResult(document.WithSyntaxRoot(root.ReplaceNodes(instanceConstructors, replacementForNodes)));
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:13,代码来源:CA1012CodeFixProvider.cs

示例3: AddModifiers

        private SyntaxNode AddModifiers(SyntaxNode node, SyntaxToken syntaxToken)
        {
            // Get the first child node.
            SyntaxNode firstNode = node.ChildNodes().FirstOrDefault();

            if (firstNode != null)
            {
                // The leading trivia will be the method comments, if any.
                SyntaxTriviaList leadingTrivia = firstNode.GetLeadingTrivia();

                // Replace it with one without leading trivia.
                node = node.ReplaceNodes(
                    new[] { firstNode },
                    (a, b) => firstNode.WithLeadingTrivia());

                // Add the leading trivia to the new modifier.
                syntaxToken = syntaxToken.WithLeadingTrivia(leadingTrivia);
            }

            return node.AddModifiers(syntaxToken);
        }
开发者ID:grokys,项目名称:StyleCopMagic,代码行数:21,代码来源:SA1400.cs

示例4: ComputeNewRootNode

#pragma warning restore 0414
    // ReSharper restore InconsistentNaming

    protected override SyntaxNode ComputeNewRootNode(SyntaxNode rootNode)
    {
      var namespaceDeclarations = rootNode.DescendantNodes().OfType<NamespaceDeclarationSyntax>();
      return rootNode.ReplaceNodes(namespaceDeclarations, (n1, n2) => ComputeNewNamespaceDeclarationNode(n1));
    }
开发者ID:cdycdr,项目名称:RoslynGenerators,代码行数:8,代码来源:AsyncGenerator.cs


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