I have successfully received an ITypeSymbol from a SyntaxNode by using:
SemanticModel.GetTypeInfo(sytaxNode).ConvertedType
Now I would like to
You can get the INamedTypeSymbol
for a type name with Compilation.GetTypeByMetadataName()
.
So try this:
semanticModel.GetTypeInfo(sytaxNode).ConvertedType.Equals(
semanticModel.Compilation.GetTypeByMetadataName(typeof(WhateverType).FullName))
This won't work with closed generic types, for those you'll need to do a bit more. For example:
var ienumerableType = semanticModel.Compilation.GetTypeByMetadataName("System.Collections.Generic.IEnumerable`1");
var intType = semanticModel.Compilation.GetTypeByMetadataName("System.Int32");
var type = ienumerableType.Construct(intType);