C# determine a Nullable property DateTime type whe

2019-04-19 05:54发布

I have a question on how to determine an object's Nullable property type.

ObjectA with a property DateTime? CreateDate;

when i am iterate through it's properties like the following code, how do I check if a property is a Nullable DateTime type?

thanks

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

3条回答
We Are One
2楼-- · 2019-04-19 06:24
pi.PropertyType == typeof(DateTime?)
查看更多
甜甜的少女心
3楼-- · 2019-04-19 06:29
pi.PropertyType == typeof(Nullable<DateTime>);
查看更多
走好不送
4楼-- · 2019-04-19 06:39

Try:

property.PropertyType.Equals(typeof(DateTime?))
查看更多
登录 后发表回答