I am trying to serialize a list of descendants. This is what I have now, that works fine:
class Animal {}
class Zebra:Animal{}
class Hippo:Animal{}
[XmlRootAttribute("Zoo")]
class Zoo
{
[XmlArrayItem(typeof(Zebra))]
[XmlArrayItem(typeof(Hippo))]
public List<Animal> Actions
{ set; get; }
}
This works fine and I can serialize both Animal
s. I wonder If it is possible to create an Attribute
class where I can pass the list of animals (instances), and will create for me the XmlArrayItem
s attributes.
In general, I am looking for a way to avoid specifying the descendants of Animal
everytime I create a new one. I want all descendants of Animal
to be serialized, whatever their type.