I\'m trying to serialize a List of multiple elements (Suppliers, Customers, Products, etc), all deriving from the same class (MasterElement)
public class XML
You can use XmlArrayItem to get around this:
public class XMLFile
{
[XmlArray("MasterFiles")]
[XmlArrayItem("Supplier", typeof(Supplier))]
[XmlArrayItem("Customer", typeof(Customer))]
public List<MasterElement> MasterFiles;
}
From the linked MSDN:
The XmlArrayItemAttribute supports polymorphism--in other words, it allows the XmlSerializer to add derived objects to an array.