获取给定框架System.Type的c#特定名称?

lan*_*nce 4 c# types

我有一个类型(例如通过反射).

我有Name属性的值,例如,String ...即"System.String".我想看"string"("int"而不是"System.Int32"等等).

框架(或语言)中的任何东西都可以给我这个吗?我可以将框架类型名称转换为语言类型名称(或者,或者,首先获取语言类型名称)?

que*_*rin 8

您可以使用CodeDom类获取特定于语言的类型别名

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
Run Code Online (Sandbox Code Playgroud)