How to get the syntax node, given a location #53746
-
I am currently learning roslyn source generator. What I intend to make is a source generator that automatically implements interfaces property member when a type interit interface but corresponding members are not implemented. The automaticlly implemented members will be autoproperty by default. What I have done so far:
As you can see I am stuck on finding the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
the location type has a reference to the syntax tree the location comes from. You need to get the "Root" node (the first node in the tree) and then call FindNode on the root to get the nearest child node at the given span. Should look something like this: foreach (Location location in Locations) {
SyntaxNode rootNode = location.SourceTree.GetRoot();
SyntaxNode nodeAtLocation = rootNode.FindNode(location.SourceSpan);
} |
Beta Was this translation helpful? Give feedback.
the location type has a reference to the syntax tree the location comes from. You need to get the "Root" node (the first node in the tree) and then call FindNode on the root to get the nearest child node at the given span. Should look something like this: