So I have a list of different Xml elements under a parent sort of like this:
<Group>
<Circle Radius="5"/>
<Rectangle Height="10" Width="15"/>
<Rectangle Height="7" Width="8"/>
<Circle Radius="12"/>
</Group>
And the classes:
public class Group
{
[XmlElement("Circle")]
public List<Circle> Circles { get; set;}
[XmlElement("Rectangle")]
public List<Circle> Circles { get; set;}
}
public class Circle
{
// The position it was encountered in the list of elements
public int Position { get; set; }
[XmlAttribute("Radius")]
public string Radius { get; set;}
}
public class Rectangle
{
// The position it was encountered in the list of elements
public int Position { get; set; }
[XmlAttribute("Width")]
public string Width { get; set; }
[XmlAttribute("Length")]
public string Length { get; set; }
}
So essentially what I'd like to do here is to save the order in which these different elements occurred as child elements under their parent, saving their place in the position integer. The only solution I can think of is to have a static variable that counts instantiations of these objects and set the position by using the count of said variable. I'd like to believe there is a 'cleaner' way of handling this and would appreciate any suggestions.
Edit: To be more clear as to where I'm going with this I want to take the two lists (because they are different objects with different attributes) and convert them to another class with a shared base class. So I have a list of these base class elements that are ordered the same as they were declared in xml so that I can draw them to the screen in that order (think a stackpanel). So if inheritance is possible during Xml deserialization that may also fix my problem if they can automatically be parsed into a list of the base class.