Get the type name

后端 未结 10 843
星月不相逢
星月不相逢 2020-12-05 23:05

How i can get full right name of generic type?

For example: This code

typeof(List).Name

return

10条回答
  •  攒了一身酷
    2020-12-05 23:45

    If you have an instance of the list, you can call .ToString() and get the following

    System.Collections.Generic.List`1[System.String]
    

    This is in addition to the methods provided by the other answers directly against the type rather than the instance.

    Edit: On your edit, I do not believe it is possible without providing your own parsing method, as List is C# shorthand for how the type is implemented, sort of like if you wrote typeof(int).ToString(), what is captured is not "int" but the CTS name, System.Int32.

提交回复
热议问题