I have a class with properties as objects of some other classes. For example:
public Class Humans { public Person Human {get; set;} [DefaulValue("New York")] public string Sity {get; set;} } public struct Person { [DefaulValue("Name")] public string Name {get; set;} [DefaulValue("Surname ")] public string Surname {get; set;} } If I want to reset the value of the Humans class, then I write this:
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(Humans); foreach (PropertyDescriptor pr in props) { if (pr.Attributes.OfType<DefaultValueAttribute>().Any()) { pr.ResetValue(obj); } } In the case of the Sity property, everything is fine, but nothing happens for the Human property. So, how to reset the default values of such properties?
DefaultValue(null)not suitable? Or do you haveHumanby default notnull? - Raider