1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
|
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);
|