private TypeSyntax GetTypeSyntax(SemanticDocument document, DocumentOptionSet options, ExpressionSyntax expression, bool isConstant, CancellationToken cancellationToken) { var typeSymbol = GetTypeSymbol(document, expression, cancellationToken); if (typeSymbol.ContainsAnonymousType()) { return(SyntaxFactory.IdentifierName("var")); } if (!isConstant && CanUseVar(typeSymbol) && TypeStyleHelper.IsImplicitTypePreferred(expression, document.SemanticModel, options, cancellationToken)) { return(SyntaxFactory.IdentifierName("var")); } return(typeSymbol.GenerateTypeSyntax()); }
private static TypeSyntax GenerateTypeSyntax(ITypeSymbol type, OptionSet options, ExpressionSyntax expression, SemanticModel semanticModel, CancellationToken cancellationToken) { // if there isn't a semantic model, we cannot perform further analysis. if (semanticModel != null) { if (type.ContainsAnonymousType()) { return(SyntaxFactory.IdentifierName("var")); } if (type.TypeKind != TypeKind.Delegate && TypeStyleHelper.IsImplicitTypePreferred(expression, semanticModel, options, cancellationToken)) { return(SyntaxFactory.IdentifierName("var")); } } return(type.GenerateTypeSyntax()); }