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?

  • How is DefaultValue(null) not suitable? Or do you have Human by default not null ? - Raider
  • @Raider, the default in the properties of Human, I specify the values. When resetting defaults in the Humans class, I want the defaults to occur in Human. - Naf

0