本文整理汇总了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));
}
示例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)));
}
示例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);
}
示例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));
}