dotnet xml:
Hi,
I am trying to use xml serialization to simplify load/save functions
in some classes i have created and am hitting a few problems. Any help
to either would be most appreciated.
I have created a MasterShape class which contains a name, and a
'Shapes' class object, which itself uses the ICollection interface to
provide a class which is basically an array of shapes i derive from an
abstract base class AbShape, for example i derive Rectangle and Circle
from AbShape and wish to be able to store any combination of these
shapes..
The problems..
1)
As far as i know classes which implement the ICollection interface do
not get their properties serialized, hence why i have made the
collection class a member of a parent class.
However, when i output the xml i get something like this:
<MasterShape Name="TwoRectangles">
<Shapes>
<Rectangle position="0,0", dimensions="20,30" />
<Rectangle position="5,5", dimensions="10,20" />
</Shapes>
</MasterShape>
However, i do not want the <Shapes> element to appear... is there any
way to serialise the shape class (e.g. the objects contained in the
collection) without creating the <Shapes> element?
Desired output:
<MasterShape Name="TwoRectangles">
<Rectangle position="0,0", dimensions="20,30" />
<Rectangle position="5,5", dimensions="10,20" />
</MasterShape>
2)
The other problem i have is that when the collection class contains an
abstract class which may contain Rectangle or Circle objects, it seems
to crash with 'error generating xml document'.
When the collection is set to be all of type Rectangle or Circle it
works...
Is there a way to allow derived classes to be stored and serialized
according to the properties of the concrete class?
*whew*
Any help would be much appreciated here. Cheers again.