If you want to serialize a polymorphic property to/from XML using XMLSerializer, you need to provide it with the required info about the derived classes. This is done with XmlElement for individual elements, and with XmlArrayItem for list items.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
public class Container { [XmlElement("d1", typeof(Derived1))] [XmlElement("d2", typeof(Derived2))] public Base base; [XmlArrayItem("b", typeof(Base))] [XmlArrayItem("d1", typeof(Derived1))] [XmlArrayItem("d2", typeof(Derived2))] public Base[] base_list; } [XmlInclude(typeof(Derived1))] [XmlInclude(typeof(Derived2))] public class Base {} public class Derived1 : Base {} |
