Any good sample on how to serialize list of generic objects with abstract base class. Samples with non abstract base class are listed in XML Serialize generic list of serializable objects. My base class is similar to Microsoft.Build.Utilities.Task
Share
It is often useful to have abstract classes with several derived types to allow use of strongly typed lists and the such.
For example you might have a DocumentFragment class which is abstract and two concrete classes called TextDocumentFragment and CommentDocumentFragment (this example from Willis).
This allows the creation of a List property which can contain objects only of those two types.
If you attempt to create a WebService that returns this list you get an error but this is easy to get around with the code below….
The XmlInclude attributes tell the class that it might be serialized to those two derived classes.
This generates an attribute in the DocumentFragment element specifying the actual type, as below.
Any additonal properties specific to the derived class will also be included using this method.