public static bool IsTypeInferred(this VariableDeclaratorSyntax variable, SemanticModel semanticModel) { var variableTypeName = variable.GetVariableType(); if (variableTypeName == null) { return(false); } return(variableTypeName.IsTypeInferred(semanticModel)); }
private IEnumerable<ITypeSymbol> InferTypeInVariableDeclarator(VariableDeclaratorSyntax variableDeclarator) { var variableType = variableDeclarator.GetVariableType(); if (variableType == null) { return SpecializedCollections.EmptyEnumerable<ITypeSymbol>(); } var types = GetTypes(variableType).Where(t => !IsUnusableType(t)); if (variableType.IsVar) { var variableDeclaration = variableDeclarator.Parent as VariableDeclarationSyntax; if (variableDeclaration != null) { if (variableDeclaration.IsParentKind(SyntaxKind.UsingStatement)) { // using (var v = Foo()) return SpecializedCollections.SingletonEnumerable(this.Compilation.GetSpecialType(SpecialType.System_IDisposable)); } if (variableDeclaration.IsParentKind(SyntaxKind.ForStatement)) { // for (var v = Foo(); .. return SpecializedCollections.SingletonEnumerable(this.Compilation.GetSpecialType(SpecialType.System_Int32)); } // Return the types here if they actually bound to a type called 'var'. return types.Where(t => t.Name == "var"); } } return types; }