本文整理汇总了C#中Solution.WithDocumentSyntaxRoot方法的典型用法代码示例。如果您正苦于以下问题:C# Solution.WithDocumentSyntaxRoot方法的具体用法?C# Solution.WithDocumentSyntaxRoot怎么用?C# Solution.WithDocumentSyntaxRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Solution
的用法示例。
在下文中一共展示了Solution.WithDocumentSyntaxRoot方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateSymbolToDeclarationAnnotationMap
private Dictionary<ISymbol, SyntaxAnnotation> CreateSymbolToDeclarationAnnotationMap(
IEnumerable<ISymbol> includedMembers,
ref Solution solution,
out List<DocumentId> documentIds,
SyntaxNode typeNode,
out SyntaxAnnotation typeNodeAnnotation,
CancellationToken cancellationToken)
{
var symbolToDeclarationAnnotationMap = new Dictionary<ISymbol, SyntaxAnnotation>();
var currentRoots = new Dictionary<SyntaxTree, SyntaxNode>();
documentIds = new List<DocumentId>();
var typeNodeRoot = typeNode.SyntaxTree.GetRoot(CancellationToken.None);
typeNodeAnnotation = new SyntaxAnnotation();
currentRoots[typeNode.SyntaxTree] = typeNodeRoot.ReplaceNode(typeNode, typeNode.WithAdditionalAnnotations(typeNodeAnnotation));
documentIds.Add(solution.GetDocument(typeNode.SyntaxTree).Id);
foreach (var includedMember in includedMembers)
{
var location = includedMember.Locations.Single();
var tree = location.SourceTree;
SyntaxNode root;
if (!currentRoots.TryGetValue(tree, out root))
{
root = tree.GetRoot(cancellationToken);
documentIds.Add(solution.GetDocument(tree).Id);
}
var token = root.FindToken(location.SourceSpan.Start);
var annotation = new SyntaxAnnotation();
symbolToDeclarationAnnotationMap.Add(includedMember, annotation);
currentRoots[tree] = root.ReplaceToken(token, token.WithAdditionalAnnotations(annotation));
}
foreach (var root in currentRoots)
{
var document = solution.GetDocument(root.Key);
solution = solution.WithDocumentSyntaxRoot(document.Id, root.Value, PreservationMode.PreserveIdentity);
}
return symbolToDeclarationAnnotationMap;
}
示例2: RemoveAwaitFromCallersAsync
private async Task<Solution> RemoveAwaitFromCallersAsync(
Solution currentSolution, IGrouping<Document, ReferenceLocation> group, CancellationToken cancellationToken)
{
var document = group.Key;
var syntaxFactsService = document.GetLanguageService<ISyntaxFactsService>();
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var editor = new SyntaxEditor(root, currentSolution.Workspace);
foreach (var location in group)
{
RemoveAwaitFromCallerIfPresent(editor, syntaxFactsService, root, location, cancellationToken);
}
var newRoot = editor.GetChangedRoot();
return currentSolution.WithDocumentSyntaxRoot(document.Id, newRoot);
}
示例3: TryCreateUpdatedSolution
//.........这里部分代码省略.........
{
includeDefinitionLocations = false;
}
}
// Find and annotate all the relevant definitions
if (includeDefinitionLocations)
{
foreach (var def in symbolWithSyntacticParameters.Locations)
{
DocumentId documentId;
SyntaxNode nodeToUpdate;
if (!TryGetNodeWithEditableSignatureOrAttributes(def, updatedSolution, out nodeToUpdate, out documentId))
{
continue;
}
if (!nodesToUpdate.ContainsKey(documentId))
{
nodesToUpdate.Add(documentId, new List<SyntaxNode>());
}
AddUpdatableNodeToDictionaries(nodesToUpdate, documentId, nodeToUpdate, definitionToUse, symbolWithSemanticParameters);
}
}
// Find and annotate all the relevant references
foreach (var location in symbol.Locations)
{
if (location.Location.IsInMetadata)
{
hasLocationsInMetadata = true;
continue;
}
DocumentId documentId2;
SyntaxNode nodeToUpdate2;
if (!TryGetNodeWithEditableSignatureOrAttributes(location.Location, updatedSolution, out nodeToUpdate2, out documentId2))
{
continue;
}
if (!nodesToUpdate.ContainsKey(documentId2))
{
nodesToUpdate.Add(documentId2, new List<SyntaxNode>());
}
AddUpdatableNodeToDictionaries(nodesToUpdate, documentId2, nodeToUpdate2, definitionToUse, symbolWithSemanticParameters);
}
}
if (hasLocationsInMetadata)
{
var notificationService = context.Solution.Workspace.Services.GetService<INotificationService>();
if (!notificationService.ConfirmMessageBox(FeaturesResources.ThisSymbolHasRelatedDefinitionsOrReferencesInMetadata, severity: NotificationSeverity.Warning))
{
return false;
}
}
// Construct all the relevant syntax trees from the base solution
var updatedRoots = new Dictionary<DocumentId, SyntaxNode>();
foreach (var docId in nodesToUpdate.Keys)
{
var doc = updatedSolution.GetDocument(docId);
var updater = doc.Project.LanguageServices.GetService<AbstractChangeSignatureService>();
var root = doc.GetSyntaxRootAsync(CancellationToken.None).WaitAndGetResult(CancellationToken.None);
var nodes = nodesToUpdate[docId];
var newRoot = root.ReplaceNodes(nodes, (originalNode, potentiallyUpdatedNode) =>
{
return updater.ChangeSignature(doc, definitionToUse[originalNode], potentiallyUpdatedNode, originalNode, CreateCompensatingSignatureChange(definitionToUse[originalNode], options.UpdatedSignature), cancellationToken);
});
var annotatedNodes = newRoot.GetAnnotatedNodes<SyntaxNode>(syntaxAnnotation: changeSignatureFormattingAnnotation);
var formattedRoot = Formatter.Format(
newRoot,
changeSignatureFormattingAnnotation,
doc.Project.Solution.Workspace,
options: null,
rules: GetFormattingRules(doc),
cancellationToken: CancellationToken.None);
updatedRoots[docId] = formattedRoot;
}
// Update the documents using the updated syntax trees
foreach (var docId in nodesToUpdate.Keys)
{
updatedSolution = updatedSolution.WithDocumentSyntaxRoot(docId, updatedRoots[docId]);
}
return true;
}
示例4: GetSolutionWithUpdatedOriginalType
internal override Solution GetSolutionWithUpdatedOriginalType(
Solution solutionWithFormattedInterfaceDocument,
INamedTypeSymbol extractedInterfaceSymbol,
IEnumerable<ISymbol> includedMembers,
Dictionary<ISymbol, SyntaxAnnotation> symbolToDeclarationAnnotationMap,
List<DocumentId> documentIds,
SyntaxAnnotation typeNodeAnnotation,
DocumentId documentIdWithTypeNode,
CancellationToken cancellationToken)
{
var documentWithTypeNode = solutionWithFormattedInterfaceDocument.GetDocument(documentIdWithTypeNode);
var root = documentWithTypeNode.GetCSharpSyntaxRootAsync(cancellationToken).WaitAndGetResult(cancellationToken);
var typeDeclaration = root.GetAnnotatedNodes<TypeDeclarationSyntax>(typeNodeAnnotation).Single();
var docId = solutionWithFormattedInterfaceDocument.GetDocument(typeDeclaration.SyntaxTree).Id;
var implementedInterfaceTypeSyntax = extractedInterfaceSymbol.TypeParameters.Any()
? SyntaxFactory.GenericName(
SyntaxFactory.Identifier(extractedInterfaceSymbol.Name),
SyntaxFactory.TypeArgumentList(SyntaxFactory.SeparatedList(extractedInterfaceSymbol.TypeParameters.Select(p => SyntaxFactory.ParseTypeName(p.Name)))))
: SyntaxFactory.ParseTypeName(extractedInterfaceSymbol.Name);
var baseList = typeDeclaration.BaseList ?? SyntaxFactory.BaseList();
var updatedBaseList = baseList.WithTypes(SyntaxFactory.SeparatedList(baseList.Types.Union(new[] { SyntaxFactory.SimpleBaseType(implementedInterfaceTypeSyntax) })));
if (!baseList.Types.Any())
{
// If we're adding the first element to the base list, then we need to move
// trivia from the type name itself to the end of the base list
updatedBaseList = updatedBaseList.WithLeadingTrivia(SyntaxFactory.Space);
if (typeDeclaration.TypeParameterList != null)
{
updatedBaseList = updatedBaseList.WithTrailingTrivia(typeDeclaration.TypeParameterList.GetTrailingTrivia());
typeDeclaration = typeDeclaration.WithTypeParameterList(typeDeclaration.TypeParameterList.WithoutTrailingTrivia());
}
else
{
updatedBaseList = updatedBaseList.WithTrailingTrivia(typeDeclaration.Identifier.TrailingTrivia);
typeDeclaration = typeDeclaration.WithIdentifier(typeDeclaration.Identifier.WithTrailingTrivia());
}
}
var updatedTypeDeclaration = typeDeclaration.WithBaseList(updatedBaseList.WithAdditionalAnnotations(Formatter.Annotation));
var updatedRoot = root.ReplaceNode(root.GetAnnotatedNodes<TypeDeclarationSyntax>(typeNodeAnnotation).Single(), updatedTypeDeclaration);
var solutionWithOriginalTypeUpdated = solutionWithFormattedInterfaceDocument.WithDocumentSyntaxRoot(docId, updatedRoot, PreservationMode.PreserveIdentity);
return solutionWithOriginalTypeUpdated;
}