private static ITypeSymbol GetRegularExpressionType(SemanticModel semanticModel, SyntaxNode node) { // regular case. always use ConvertedType to get implicit conversion right. var expression = node.GetUnparenthesizedExpression(); var info = semanticModel.GetTypeInfo(expression); var conv = semanticModel.GetConversion(expression); if (info.ConvertedType == null || info.ConvertedType.IsErrorType()) { // there is no implicit conversion involved. no need to go further return info.Type; } // always use converted type if method group if ((!node.IsKind(SyntaxKind.ObjectCreationExpression) && semanticModel.GetMemberGroup(expression).Length > 0) || IsCoClassImplicitConversion(info, conv, semanticModel.Compilation.CoClassType())) { return info.ConvertedType; } // check implicit conversion if (conv.IsImplicit && (conv.IsConstantExpression || conv.IsEnumeration)) { return info.ConvertedType; } // always try to use type that is more specific than object type if possible. return !info.Type.IsObjectType() ? info.Type : info.ConvertedType; }