Exemple #1
0
        public static TypeSyntax ToTypeSyntax(this ITypeSymbol symbol, IGenerationContext context)
        {
            if (symbol == null)
            {
                throw new ArgumentNullException(nameof(symbol));
            }

            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            context.AddEmittedType(symbol);
            if (symbol is INamedTypeSymbol namedTypeSymbol)
            {
                foreach (var typeArgument in namedTypeSymbol.TypeArguments)
                {
                    typeArgument.ToTypeSyntax(context);
                    if (typeArgument.Kind == SymbolKind.TypeParameter)
                    {
                        context.AddGenericType(typeArgument.Name);
                    }
                }
            }

            return(SyntaxFactory.ParseTypeName(symbol.ToDisplayString(new SymbolDisplayFormat(
                                                                          SymbolDisplayGlobalNamespaceStyle.Omitted,
                                                                          SymbolDisplayTypeQualificationStyle.NameAndContainingTypes,
                                                                          SymbolDisplayGenericsOptions.IncludeTypeParameters,
                                                                          miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes))));
        }