Get the C # -specific name for this System.Type structure?

I have a Type (through reflection, for example).

I have a value for the Name property, for example String ... that "System.String". I want to see "string" ("int" instead of "System.Int32" etc. Etc.).

Can anything in the framework (or language) give me this? Can I convert the name of the Framework type to the name of the language type (or, conversely, get the name of the language type to start with)?

+4
source share
1 answer

Using CodeDom Classes

you can get individual aliases of language types,
var cs = new CSharpCodeProvider(); var vb = new VBCodeProvider(); var type = typeof (int); Console.WriteLine("Type Name: {0}", type.Name); // Int32 Console.WriteLine("C# Type Name: {0}", cs.GetTypeOutput(new CodeTypeReference(type))); // int Console.WriteLine("VB Type Name: {0}", vb.GetTypeOutput(new CodeTypeReference(type))); // Integer 
+8
source

All Articles