views:

89

answers:

1

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)?

+8  A: 

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
qstarin