本文整理汇总了C#中IDocument.UpdateSyntaxRoot方法的典型用法代码示例。如果您正苦于以下问题:C# IDocument.UpdateSyntaxRoot方法的具体用法?C# IDocument.UpdateSyntaxRoot怎么用?C# IDocument.UpdateSyntaxRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocument
的用法示例。
在下文中一共展示了IDocument.UpdateSyntaxRoot方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Annotate
public static IDocument Annotate(IDocument document, TextSpan span, out IEnumerable<SyntaxAnnotation> annotations)
{
var oldRoot = (CompilationUnitSyntax)document.GetSyntaxRoot();
var propertyAnnotater = new PropertyAnnotater(document, span);
var newRoot = (CompilationUnitSyntax)propertyAnnotater.Visit(oldRoot);
annotations = propertyAnnotater.annotations;
return document.UpdateSyntaxRoot(newRoot);
}
示例2: updateMethodInvocations
/// <summary>
/// Update all the method invocations in the solution.
/// </summary>
/// <param name="document"></param>
/// <returns></returns>
private IDocument updateMethodInvocations(IDocument document)
{
// Get the retriever for method invocations.
var retriever = RetrieverFactory.GetMethodInvocationRetriever();
retriever.SetMethodDeclaration(declaration);
// Get all the invocations in the document for the given method
// declaration.
retriever.SetDocument(document);
var invocations = retriever.GetInvocations();
// If there are invocations in the document.
if (invocations.Any())
{
// Update root
var root = (SyntaxNode) document.GetSyntaxRoot();
var updatedRoot = new InvocationsAddArgumentsRewriter(invocations,
typeNameTuple.Item2).Visit(root);
// Update solution by update the document.
document = document.UpdateSyntaxRoot(updatedRoot);
}
return document;
}
示例3: updateMethodDeclaration
private IDocument updateMethodDeclaration(IDocument document)
{
// Get the simplified name of the method
var methodName = ((MethodDeclarationSyntax) declaration).Identifier.ValueText;
var documentAnalyzer = AnalyzerFactory.GetDocumentAnalyzer();
documentAnalyzer.SetDocument(document);
// Get the root of the current document.
var root = ((SyntaxNode) document.GetSyntaxRoot());
// Find the method
SyntaxNode method = root.DescendantNodes().Where(
// Find all the method declarations.
n => n.Kind == SyntaxKind.MethodDeclaration).
// Convert all of them to the RefactoringType MethodDeclarationSyntax.
Select(n => (MethodDeclarationSyntax) n).
// Get the one whose name is same with the given method declaration.
First(m => m.Identifier.ValueText.Equals(methodName));
// If we can find this method.
if (method != null)
{
// Get the updated method declaration.
var methodAnalyzer = AnalyzerFactory.GetMethodDeclarationAnalyzer();
methodAnalyzer.SetMethodDeclaration(method);
var updatedMethod = methodAnalyzer.AddParameters(new[] {typeNameTuple});
// Update the root, document and finally return the code action.
var updatedRoot = new MethodDeclarationRewriter(method, updatedMethod).
Visit(root);
return document.UpdateSyntaxRoot(updatedRoot);
}
return document;
}