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

前端 未结 3 959
栀梦
栀梦 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
    慢半拍i (楼主)
    2021-02-12 20:14

    I couldn't find something built-in either and I'm quite sure this isn't the most elegant way, but it worked for me to construct a qualified type name like this:

    private static string GetQualifiedTypeName(ISymbol symbol)
    {
        return symbol.ContainingNamespace 
            + "." + symbol.Name 
            + ", " + symbol.ContainingAssembly;
    }
    

    If you don't need an assembly qualified type name don't concatenate ContainingAssembly at the end of the last line.

提交回复
热议问题