Calling code

typeof(int).Name 

I get "Int32"

How do I get short type names? That is, instead of Int32 - int, Int64 - long and so on. Manual mapping does not offer, I myself can. Just thought, maybe there is a more beautiful solution.

  • there is no such thing, since these are aliases and after compilation they simply do not exist - Grundy

1 answer 1

You can use Microsoft.CSharp.CSharpCodeProvider.GetTypeOutput

 var compiler = new CSharpCodeProvider(); var type = new CodeTypeReference(typeof(int)); Console.WriteLine(typeof(int).Name); Console.WriteLine(compiler.GetTypeOutput(type)); 

Output:

 Int32 int 
  • found a solution on so - Ruslan_K