2014-03-25 64 views
0

我有一个类数据类型

namespace MyNamespace1 
{ 
    class MyClass 
    { 
     public string MyName { get; set; } 
     public int? MaxHeaderLength { get; set; } 
     public System.Collections.Generic.List<MyClass.ViewModel> Preferences { get; set; } 
    } 
} 

namespace MyNamespace2 
{ 
    internal class myClass1 
    { 
     public static void Main(string[] args) 
     { 
      var properties = loading assembly of the MyClass of MyNamespace1 
      var prop = properties.GetProperties(); 
      foreach (var propertyInfo in prop) 
      { 
       Console.WriteLine(propertyInfo.PropertyType.FullName); 

      } 
     } 
    } 
} 

当我想用反射

我收到类型为

阅读在运行时的性能

System.String,

System.Nullable`1 [[System.Int32,mscorlib程序,版本= 4.0.0.0, 文化=中性公钥= b77a5c561934e089]],

System.Collections.Generic.List`1 [[System.Web.Mvc.SelectListItem, System.Web.Mvc,版本= 3.0.0.0,文化=中性, 公钥= 31bf3856ad364e35]]),

但我想找回作为

string, 

int?, 

System.Collections.Generic.List<MyClass.ViewModel> 

可有人请我提供的解决方案。

+1

你想*友好的名字*。检查http://stackoverflow.com/questions/16466380/get-user-friendly-name-for-generic-type-in​​-c-sharp和http://stackoverflow.com/questions/4615553/c-sharp-get - 用户友好的名称 - 的 - 简单的类型,通过反射 – Maarten

回答

0

string,int?List<MyClass.ViewModel>都是C#构造。他们不在.NET本身。

所以你只需建立一个查找表或一个巨大的switch将类型名称转换为.NET关键字。