If I have an expression producing a result, say, new ClassA(), or "somestring", or whatever, and I have a corresponding ExpressionSyntax object, how do I get the INamedTypeSymbol object corresponding to the result of the expression?
Many tutorials mention the GetTypeInfo method, but I cannot find it in the latest Roslyn I got from NuGet. Is there something that replaces it?
Update: Somehow I had the 1.0 version of Roslyn. After updating it to 1.2, I found the GetTypeInfo method.
You need to build the semantic model, like this:
var semanticModel = document.GetSemanticModel(cancellationToken);
var typeInfo = semanticModel.GetTypeInfo(expression, cancellationToken);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With