本文介绍了C#确定可空属性DateTime类型使用反射时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对如何确定对象的可空属性类型的问题。
对象A
与属性
日期时间? CREATEDATE;
当我通过它的属性,如下面的代码重复,我该如何检查,如果一个属性是可空DateTime类型?
感谢
的foreach(PI的PropertyInfo在ObjectA.GetType() .GetProperties())
{
//做比较这里
}
解决方案
pi.PropertyType == typeof运算(日期时间?)
I have a question on how to determine an object's Nullable property type.
ObjectAwith a propertyDateTime? 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
}
解决方案
pi.PropertyType == typeof(DateTime?)
这篇关于C#确定可空属性DateTime类型使用反射时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!