[英]What is the "GlobalStatementSyntax" syntax node type in Roslyn
I was investigating classes of syntax nodes which implement MemberDeclarationSyntax
in Roslyn and encountered GlobalStatementSyntax
class.我正在研究在 Roslyn 中实现
MemberDeclarationSyntax
的语法节点类,并遇到了GlobalStatementSyntax
类。 What kind of code generates syntax tree with GlobalStatementSyntax
nodes?什么样的代码生成带有
GlobalStatementSyntax
节点的语法树? And why GlobalStatementSyntax
is derived from MemberDeclarationSyntax
?为什么
GlobalStatementSyntax
派生自MemberDeclarationSyntax
? Can such node represent a member of a type?这样的节点可以代表一个类型的成员吗?
Two minutes of experimentation confirmed that you get those if you use the new Top-level statements feature.两分钟的实验证实,如果您使用新的顶级语句功能,您会得到这些。 That is, if your entire program is:
也就是说,如果您的整个程序是:
Console.WriteLine(args.Count);
(With no class
, no void Main
, etc) (没有
class
,没有void Main
等)
Then the Roslyn Quoter generates this structure:然后Roslyn Quoter生成这个结构:
CompilationUnit()
.WithMembers(
SingletonList<MemberDeclarationSyntax>(
GlobalStatement(
ExpressionStatement(
InvocationExpression(
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
IdentifierName("Console"),
IdentifierName("WriteLine")))
.WithArgumentList(
ArgumentList(
SingletonSeparatedList<ArgumentSyntax>(
Argument(
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
IdentifierName("args"),
IdentifierName("Count"))))))))))
.NormalizeWhitespace()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.