2009-07-24 36 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?)) 
相關問題