在C#代码分析中,如何知道typesyntax是否是枚举?
在我的代码中,我已经捕获了此typeyntax,这是标识的Namesyntax。如图所示,在“属性”下,这是一个枚举,分类为“枚举名称”。但是我不知道该如何在我的程序中得到这个。似乎与语义模型有关。
它是在给定的genoratoreXecutionContext上下文
下完成的,因此可以获取语义模型context.compilation.getSemanticmodel(typeyntax.syntaxtree)
,您不必担心。
In my code, I have already captured this TypeSyntax, which is an IdentifierNameSyntax. It is an Enum, as shown in the image, under "Properties", the Classification is "Enum Name". But I don't know how to get this in my program. Seem like it have something to do with the semantic model.
It was done under given GeneratorExecutionContext context
, so semantic model can be get context.Compilation.GetSemanticModel(typeSyntax.SyntaxTree)
, you don't need to worry about that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在正确的轨道上!
目前,您手头上有句法信息,您确实可以通过 Semanticmodel 。
,要求 typeInfo
首先 获取有关 ,例如 api/system.int32“ rel =“ nofollow noreferrer”> int 默认值:
You are on the right track!
Currently you have the syntactic information in hand, and you may indeed query semantic information through the SemanticModel.
First, ask for the TypeInfo of that expression:
With this you can get hold of more semantic information about that enum type, such as its members and their names, or the underlying type of the enum type which is int per default: