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.
如果我有一个产生结果的表达式,比如 new ClassA() 或“somestring”,或者其他什么,并且我有一个相应的 ExpressionSyntax 对象,我如何获得与表达式结果对应的 INamedTypeSymbol 对象?
许多教程都提到了 GetTypeInfo 方法,但我在从 NuGet 获得的最新 Roslyn 中找不到它。有什么东西可以代替它吗?
更新:不知何故,我有 1.0 版的 Roslyn。更新到1.2后,找到了GetTypeInfo方法。
您需要构建语义模型,如下所示:
var semanticModel = document.GetSemanticModel(cancellationToken); var typeInfo = semanticModel.GetTypeInfo(expression, cancellationToken);