I have a Type (via reflection, for example).
I have the value of the Name property on, for example, String... that's "System.String". I want to see "string" ("int" instead of "System.Int32", etc, etc).
Can anything in the framework (or the language) give me that? Can I convert a Framework type name to a language type name (or, alternatively, get the language type name to begin with)?
You can get language specific type aliases by using CodeDom classes
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With