M
Mark Sizer
Hi people,
I'm having trouble trying to achieve something in C# and win forms, and am
looking for a little advice if anyone has a moment.
I've got two classes:
1) a base class
2) a derived class that inherits from it
The base class is designed to hold data and only data.
The derived class (which inherits the base/data) class is designed to have
more of a presentation role. It performs calculations on the data in the
base class and offers out manipulated data derived from the data in the base
class. The manipulated data is often offered through overridden properties.
That all works fine so far, now for the part I'm having problems with.
I'd like to be able to serialize both classes out as xml.
So the base class can save its data to file in xml format (and it should
save only its data, none of the presentation data).
Then the derived class can save its data to xml also, for me to match up
with an xslt file and present the data in a web brower.
The problem is, keeping the two sets of properties from the two classes
(base data and presentation data) separate and only serializing out the
fields required for the class in question.
If for example I have an object in memory as the derived class, then when I
serialize it to disk, it serializes the data from the base properties and
the data from the presentation/derived/overridden properties.
If instead I have the object in memory as the base class, then it serializes
fine, but I cannot of course access the presentation properties as they
don't exist on the base class.
Incidentally, I'm pretty confident that I've gone the right path with the
class/inheriting/serialize route for data/presentation. I'm just having
trouble getting over the final hurdle.
The only solutions that i've can think of so far is, custom attribute tags
combined with custom serialization. However, I will want to do the same
thing with several other very different classes, and it seems like one heck
of a lot of work. Can anyone suggest an easier solution?
Cheers,
Mark.
I'm having trouble trying to achieve something in C# and win forms, and am
looking for a little advice if anyone has a moment.
I've got two classes:
1) a base class
2) a derived class that inherits from it
The base class is designed to hold data and only data.
The derived class (which inherits the base/data) class is designed to have
more of a presentation role. It performs calculations on the data in the
base class and offers out manipulated data derived from the data in the base
class. The manipulated data is often offered through overridden properties.
That all works fine so far, now for the part I'm having problems with.
I'd like to be able to serialize both classes out as xml.
So the base class can save its data to file in xml format (and it should
save only its data, none of the presentation data).
Then the derived class can save its data to xml also, for me to match up
with an xslt file and present the data in a web brower.
The problem is, keeping the two sets of properties from the two classes
(base data and presentation data) separate and only serializing out the
fields required for the class in question.
If for example I have an object in memory as the derived class, then when I
serialize it to disk, it serializes the data from the base properties and
the data from the presentation/derived/overridden properties.
If instead I have the object in memory as the base class, then it serializes
fine, but I cannot of course access the presentation properties as they
don't exist on the base class.
Incidentally, I'm pretty confident that I've gone the right path with the
class/inheriting/serialize route for data/presentation. I'm just having
trouble getting over the final hurdle.
The only solutions that i've can think of so far is, custom attribute tags
combined with custom serialization. However, I will want to do the same
thing with several other very different classes, and it seems like one heck
of a lot of work. Can anyone suggest an easier solution?
Cheers,
Mark.