开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜