O
olympus_mons
Hi,
I generated C# classes from some complex XMLSchemas usind xsd.exe. The
result is that I get a class hierarchy that is quite deep (well for me
8 levels are deep). What I'm curiuos about is, that if I create an
instance of my top level element I still need to create instances of
all sub-elements. What would be the best way to do some sort of "deep
new" operator, that recursively creates instances for all sub-classes
(the complete structure consists of 89 different classes).
Lets say my class structure is like
Top
+-->Sub1
+-->Sub1_1
+-->Sub1_2
+-->Sub2
+-->Sub2_1
+-->Sub2_2
and instead of:
Top top = new Top();
top.sub1 = new Sub1();
top.sub1.sub1_1 = new Sub1_1();
top.sub1.sub1_2 = new Sub1_2();
....
just do:
Top top = new Top(true);
which will create instances for all sub-elements.
Of couse I could code a creator method that just does this. But maybe
this is not the best approach. So what would a experienced C#-guy do?
Any idea?
Thanks,
Stefan
P.S.: You probably noticed that I must be new to C#/FW2.0...
I generated C# classes from some complex XMLSchemas usind xsd.exe. The
result is that I get a class hierarchy that is quite deep (well for me
8 levels are deep). What I'm curiuos about is, that if I create an
instance of my top level element I still need to create instances of
all sub-elements. What would be the best way to do some sort of "deep
new" operator, that recursively creates instances for all sub-classes
(the complete structure consists of 89 different classes).
Lets say my class structure is like
Top
+-->Sub1
+-->Sub1_1
+-->Sub1_2
+-->Sub2
+-->Sub2_1
+-->Sub2_2
and instead of:
Top top = new Top();
top.sub1 = new Sub1();
top.sub1.sub1_1 = new Sub1_1();
top.sub1.sub1_2 = new Sub1_2();
....
just do:
Top top = new Top(true);
which will create instances for all sub-elements.
Of couse I could code a creator method that just does this. But maybe
this is not the best approach. So what would a experienced C#-guy do?
Any idea?
Thanks,
Stefan
P.S.: You probably noticed that I must be new to C#/FW2.0...