Then in our serializing Shape class we add an array of this enumeration, so it can be matched with the list being serialised. So we define a public enumeration of the different object types: The XML Serialiser then uses this to help detect what object type it is ( ).
NET makes us add an enumeration which is ignored by the XML. This is when we hit our first slightly different XML definition. Now, let's make a list of the base object and force the XML Serialiser to add the different element names (Line, Triangle, Ellipse) to the single list. Public sealed class Ellipse : DrawingObject Public sealed class Triangle : DrawingObject It still serves the point of showing different derived classes).
Scadapack isagraf workbench code#
The XmlElement is defined in these derived classes for the Serialiser (and yes, I realise the Ellipse is the same as a Line, but there's other code I removed for this example. To set the size of the Point array, I use a private field and then modify the base array to become a getter, using the 'new' keyword. Now, I derive each specific object from this base class. Because the size of the Point array changes based on each derived object, the XML Serialiser ignores the Point array in the base class. I then created a base drawing object, with a colour and a list of points. I defined my own Point class, instead of using, just so they could be represented as attributes in my XML (a design decision). Just being lazy and using on the Shape list in a C# class did not work, so I had to go deeper. The order of the XML is also the order of drawing on the screen, so I wanted these to remain in a single list as a grouping of objects, derived from a simple object class. The simple way to do this would be to have a list for each object type (Line, Ellipse, Triangle) but that's not what I wanted. I've broken the shapes down to different classes, but stuck them in a single XML list.Įach device has a shape which is a list of different drawing objects.
I've got an XML file containing a list of basic shapes I need to draw in my application.