public static string GetSemanticType()

in src/Analysis/Codelyzer.Analysis.CSharp/SemanticHelper.cs [70:98]


        public static string GetSemanticType(ExpressionSyntax expressionSyntax, 
            SemanticModel semanticModel,
            SemanticModel preportSemanticModel = null)
        {
            if (semanticModel == null && preportSemanticModel == null) return null;
            
            string type = null;

            var typeInfo = semanticModel.GetTypeInfo(expressionSyntax);
            if (typeInfo.Type == null && preportSemanticModel != null)
            {
                try
                {
                    typeInfo = preportSemanticModel.GetTypeInfo(expressionSyntax);
                }
                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;
        }