class Program
{
}
var tree = await document.GetSyntaxRootAsync();
var newTree = tree.DescendantNodesAndSelf().
OfType<ClassDeclarationSyntax>().
First().AddMembers(
SyntaxFactory.MethodDeclaration(
SyntaxFactory.PredefinedType(SyntaxFactory.Token(
SyntaxKind.VoidKeyword)),
SyntaxFactory.Identifier("Main"))
.WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(
SyntaxKind.StaticKeyword)))
.WithBody(SyntaxFactory.Block())
)
).NormalizeWhitespace();
var newDocument = document.WithSyntaxRoot(newTree);
class Program
{
static void Main()
{
}
}
var tree = await document.GetSyntaxRootAsync();
var classDeclaration = tree.DescendantNodesAndSelf().
OfType<ClassDeclarationSyntax>().First();
var semanticModel = await document.GetSemanticModelAsync();
var typeSymbol = semanticModel.GetDeclaredSymbol(classDeclaration);
var references = await SymbolFinder.FindReferencesAsync(document.Project.Solution, typeSymbol);
// process references
- **structural** information about the code
- immutable
- round-trippable
- **semantic** meaning of the syntax trees
- backed by compilation
- symbols, diagnostics, code flow..
Find issue | Change code | Diagnostic | Distribution | |
---|---|---|---|---|
Analyzer | 🔍 | 🦄 | ||
Code fix | 🔧 | 🦄 | ||
Refactoring | 🔧 |