Getting the fully qualified name of a type from a TypeInfo object

前端 未结 3 950
栀梦
栀梦 2021-02-12 19:47

Is it somehow possible to get the fully qualified name of the type contained in a TypeInfo object?

In the debugger many of these values nicely show up as

3条回答
  •  梦毁少年i
    2021-02-12 20:03

    The ToDisplayString method lets you pass in a "format" object which has a huge number of options for controlling how you want to format stuff:

    var symbolDisplayFormat = new SymbolDisplayFormat(
        typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces);
    
    string fullyQualifiedName = typeSymbol.ToDisplayString(symbolDisplayFormat);
    

    The reason your getting keywords like "int" is the default format is including the SymbolDisplayMiscellaneousOptions.UseSpecialTypes flag which specifies to use the language keywords for special types vs. the regular name.

提交回复
热议问题