Get c#-specific name for a given framework System.Type?
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 "stri开发者_开发知识库ng" ("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
精彩评论