I have two classes:
public class HumanProperties { int prop1; int prop2; string name;} public class Human{int age; HumanProperties properties;}
Now, if I want to create a new instance of Human, I need to do Human person = new Human(); But when I try to access, like person.properties.prop1=1; , then I have nullRefrence in the properties, beacuse, I must also create new properties. I have to do this:
Human person = new Human(); person.properties = new HumanProperties();
and now I can access this person.properties.prop1=1;
This was a small example, but I have a huge class created from xsd, and I don’t have much time to manually generate this “person” class with all its subclasses. Is there a way to do this programmatically or is there some kind of generator for this?
Or can I skip the class and make a new typeof type of property for each property and attach it to the parent class?
Thanks!
source share