简体   繁体   English

使用反射时,C#确定Nullable属性DateTime类型

[英]C# determine a Nullable property DateTime type when using reflection

I have a question on how to determine an object's Nullable property type. 我有一个关于如何确定对象的Nullable属性类型的问题。

ObjectA with a property DateTime? 具有DateTime属性的ObjectA? CreateDate; 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? 当我迭代它的属性,如下面的代码,我如何检查属性是否是Nullable DateTime类型?

thanks 谢谢

foreach (PropertyInfo pi in ObjectA.GetType().GetProperties())
        {
            //do the compare here
        }
pi.PropertyType == typeof(DateTime?)
pi.PropertyType == typeof(Nullable<DateTime>);

尝试:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM