2009-07-24 105 views
11

我对如何确定对象的Nullable属性类型有疑问。C#使用反射时确定Nullable属性DateTime类型

ObjectA 与财产 DateTime? CREATEDATE;

当我遍历它的属性,如下面的代码,我该如何检查属性是否为Nullable DateTime类型?

感谢

foreach (PropertyInfo pi in ObjectA.GetType().GetProperties()) 
     { 
      //do the compare here 
     } 

回答

31
pi.PropertyType == typeof(DateTime?) 
+0

谢谢〜.... :) – Eatdoku 2009-07-25 16:40:08

2
pi.PropertyType == typeof(Nullable<DateTime>); 
0

尝试:

property.PropertyType.Equals(typeof(DateTime?))