Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个代码:
public override void VisitMemberAccessExpression(MemberAccessExpressionSyntax node) { Console.WriteLine("Name: {0}", node.Name); }
如何定义节点类型?例如:如果节点类型是“产品”,那么不要写它。
顾名思义,MemberAccessExpressionSyntax它只包含关于表达式的句法信息,不包含任何关于类型的信息。
MemberAccessExpressionSyntax
如果你想获取类型信息,你需要Compilation为你的语法树(或树)创建一个并获取它的SemanticModel. 有了它,您可以执行以下操作:
Compilation
SemanticModel
semanticModel.GetTypeInfo(node).Type.Name == "Product"