lundi 17 février 2020

C# properties obtained via reflection: check if it has a default value of its type?

I am iterating an object using reflection like so:

foreach (PropertyInfo property in properties)
   {
    object prop = property.GetValue(myObjectInstance);
     // TODO: I need to check if prop carries a default value for its respective type
   }

How I can check if the prop is equal to the type's default value (for instance, if the property is of DateTime, then check for default(DateTime))?





Aucun commentaire:

Enregistrer un commentaire