本文整理汇总了C#中ISolution.UpdateDocument方法的典型用法代码示例。如果您正苦于以下问题:C# ISolution.UpdateDocument方法的具体用法?C# ISolution.UpdateDocument怎么用?C# ISolution.UpdateDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISolution
的用法示例。
在下文中一共展示了ISolution.UpdateDocument方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: updateMethodInvocations
/* Update all the method invocations in the solution. */
private ISolution updateMethodInvocations(ISolution solution)
{
// Get all the documents in the solution.
var solutionAnalyzer = AnalyzerFactory.GetSolutionAnalyzer();
solutionAnalyzer.SetSolution(solution);
var documents = solutionAnalyzer.GetAllDocuments();
// Get the retriever for method invocations.
var retriever = RetrieverFactory.GetMethodInvocationRetriever();
retriever.SetMethodDeclaration(declaration);
// For each document
foreach (var document in documents)
{
// 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, typeNameTuples.Select(t => t.Item2)).
Visit(root);
// Update solution by update the document.
solution = solution.UpdateDocument(document.Id, updatedRoot);
}
}
return solution;
}
示例2: updateMethodDeclaration
private ISolution updateMethodDeclaration(ISolution solution)
{
// Get the qualified name of the RefactoringType containing the declaration.
var qualifidedNameAnalyzer = AnalyzerFactory.GetQualifiedNameAnalyzer();
qualifidedNameAnalyzer.SetSyntaxNode(declaration);
var typeName = qualifidedNameAnalyzer.GetOutsideTypeQualifiedName();
// Get all documents in the given originalSolution.
var solutionAnalyzer = AnalyzerFactory.GetSolutionAnalyzer();
solutionAnalyzer.SetSolution(solution);
var documents = solutionAnalyzer.GetAllDocuments();
// Get the simplified name of the method
var methodName = ((MethodDeclarationSyntax) declaration).Identifier.ValueText;
// For each document in the originalSolution.
foreach (var document in documents)
{
var documentAnalyzer = AnalyzerFactory.GetDocumentAnalyzer();
documentAnalyzer.SetDocument(document);
// If the document contains the RefactoringType in which the method is declared.
if (documentAnalyzer.ContainsQualifiedName(typeName))
{
// 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(typeNameTuples);
// Update the root, document and finally return the code action.
var updatedRoot = new MethodDeclarationRewriter(method, updatedMethod).Visit(root);
return solution.UpdateDocument(document.Id, updatedRoot);
}
}
}
return solution;
}