问题
I have a question on how to determine an object's Nullable property type.
ObjectA
has a property DateTime? CreateDate;
When I iterate through its properties like the following code, how do I check if a property is a Nullable DateTime
type?
foreach (PropertyInfo pi in ObjectA.GetType().GetProperties())
{
//do the compare here
}
回答1:
pi.PropertyType == typeof(DateTime?)
回答2:
pi.PropertyType == typeof(Nullable<DateTime>);
回答3:
Try:
property.PropertyType.Equals(typeof(DateTime?))
来源:https://stackoverflow.com/questions/1180730/c-sharp-determine-a-nullable-property-datetime-type-when-using-reflection