private static TypeSyntax GenerateTypeSyntax( INamespaceOrTypeSymbol symbol, bool nameSyntax, bool allowVar = true) { var type = symbol as ITypeSymbol; if (type != null && type.ContainsAnonymousType()) { // something with an anonymous type can only be represented with 'var', regardless // of what the user's preferences might be. return(SyntaxFactory.IdentifierName("var")); } var syntax = symbol.Accept(TypeSyntaxGeneratorVisitor.Create(nameSyntax)) .WithAdditionalAnnotations(Simplifier.Annotation); if (!allowVar) { syntax = syntax.WithAdditionalAnnotations(DoNotAllowVarAnnotation.Annotation); } #if !CODE_STYLE if (type != null && type.IsReferenceType) { syntax = syntax.WithAdditionalAnnotations( type.NullableAnnotation switch { NullableAnnotation.None => NullableSyntaxAnnotation.Oblivious, NullableAnnotation.Annotated => NullableSyntaxAnnotation.AnnotatedOrNotAnnotated, NullableAnnotation.NotAnnotated => NullableSyntaxAnnotation.AnnotatedOrNotAnnotated, _ => throw ExceptionUtilities.UnexpectedValue(type.NullableAnnotation), });
private static TypeSyntax GenerateTypeSyntax( INamespaceOrTypeSymbol symbol, bool nameSyntax, bool allowVar = true) { var syntax = symbol.Accept(TypeSyntaxGeneratorVisitor.Create(nameSyntax)) .WithAdditionalAnnotations(Simplifier.Annotation); if (!allowVar) { syntax = syntax.WithAdditionalAnnotations(DoNotAllowVarAnnotation.Annotation); } return(syntax); }
private static TypeSyntax GenerateTypeSyntax( INamespaceOrTypeSymbol symbol, bool nameSyntax, bool allowVar = true) { if (symbol is ITypeSymbol type && type.ContainsAnonymousType()) { // something with an anonymous type can only be represented with 'var', regardless // of what the user's preferences might be. return(SyntaxFactory.IdentifierName("var")); } var syntax = symbol.Accept(TypeSyntaxGeneratorVisitor.Create(nameSyntax)) .WithAdditionalAnnotations(Simplifier.Annotation); if (!allowVar) { syntax = syntax.WithAdditionalAnnotations(DoNotAllowVarAnnotation.Annotation); } return(syntax); }
private static TypeSyntax GenerateTypeSyntax( INamespaceOrTypeSymbol symbol, bool nameSyntax) { return(symbol.Accept(TypeSyntaxGeneratorVisitor.Create(nameSyntax)) .WithAdditionalAnnotations(Simplifier.Annotation)); }
private static TypeSyntax GenerateTypeSyntax( INamespaceOrTypeSymbol symbol, bool nameSyntax) { return symbol.Accept(TypeSyntaxGeneratorVisitor.Create(nameSyntax)) .WithAdditionalAnnotations(Simplifier.Annotation); }
public static TypeSyntax GetTypeSyntaxForSymbol(INamespaceOrTypeSymbol symbol) { return(symbol.Accept(new TypeNameVisitor()).WithAdditionalAnnotations(Simplifier.Annotation)); }