20

我有一个关于如何确定对象的 Nullable 属性类型的问题。

ObjectA有财产DateTime? CreateDate;

当我像下面的代码一样遍历它的属性时,如何检查一个属性是否是一个Nullable DateTime类型?

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

3 回答 3

50
pi.PropertyType == typeof(DateTime?)
于 2009-07-25T00:00:33.260 回答
4
pi.PropertyType == typeof(Nullable<DateTime>);
于 2009-07-25T02:52:33.923 回答
0

尝试:

property.PropertyType.Equals(typeof(DateTime?))
于 2016-05-13T19:13:13.897 回答