in src/Analysis/Codelyzer.Analysis.CSharp/SemanticHelper.cs [176:204]
public static string GetSemanticType(IdentifierNameSyntax identifierNameSyntax,
SemanticModel semanticModel,
SemanticModel preportSemanticModel)
{
if (semanticModel == null && preportSemanticModel == null) return null;
string type = null;
var typeInfo = semanticModel.GetTypeInfo(identifierNameSyntax);
if (typeInfo.Type == null && preportSemanticModel != null)
{
try
{
typeInfo = preportSemanticModel.GetTypeInfo(identifierNameSyntax);
}
catch (Exception)
{
//When looking for a symbol, and the semantic model is not passed, this generates an error.
//We don't log this error because this is an expected behavior when there's no previous semantic models
}
}
if (typeInfo.Type != null)
{
type = typeInfo.Type.Name;
}
return type;
}