Tutorial by Examples

If you already have access to your Document class from your workspace (Using Workspaces) it is easy to access the root of your Syntax tree. Document document = ... // Get document from workspace or other source var syntaxRoot = await document.GetSyntaxRootAsync();
You can easily navigate the a Syntax Tree using LINQ. For example it is easy to get all the ClassDeclarationSyntax nodes (declared classes), that have a name starting with the letter A: var allClassesWithNameStartingWithA = syntaxRoot.DescendantNodes() .OfType<ClassDeclarationSyntax>()...
The CSharpSyntaxWalker class is out of the box implementation of the Visitor pattern, that we can use to traverse our Syntax Tree. Here is a simple example of a Syntax Walker that collects all the struct-s that have a name, starting with the letter A: public class StructCollector : CSharpSyntaxWa...

Page 1 of 1