C # type name instead of CLR type name

typeof(int).Name

      

System.Int32 will be returned does anyone know how to return "int"

+1


source to share


3 answers


There aren't many types that are C # keywords (int, double, string) ... so maybe you can write your own mapping function, from the system type name to the corresponding C # keyword.



+6


source


Yes, you could write a mapping function. It's just an alias anyway.

Here's a list:



http://msdn.microsoft.com/en-us/library/86792hfa(VS.71).aspx

+4


source


Using reflection, you can use CSharpCodeProvider

(exists in .NET Core 2 as well) to get "int", "string", etc. instead of fully qualified CLR type names.

There are other SO posts that provide code examples for this:

How can I get the primitive name of a type in C #?

C # - get convenient name of simple types by reflection?

Alternatively, you will have to match these types yourself. There are several libraries for this, if you don't mind third party libraries. Don't forget about zero value changes.

0


source







All Articles