I have an object InputFile that has arrays and objects to hold the contents of a file. I also have ABCFile and XYZFile that are both inherited from InputFile that will read different types of file and store them into the projected members of InputFile.
Since the serialization and deserialization of both of these objects are identical to the parent object, I have implemented a standard XML serialization interface on the parent object. During deserialization a few paramters are read, a Read function is called (to load a file), then the deserialization finishes.
The serialization works great, but the deserialization (of List<InputFile>) doesn't work because the deserializer calls the parents stub Read file function instead of ABCFile or XYZFile's.
How can I get the deserialization to recognize the correct type of object to use? It is possible that my List<InputFile> will have a mix of file types.
Thanks
The code I use to serialize the object:
public class InputFileHolder : IXmlSerializable {
...
public void WriteXml(XmlWriter w) {
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
XmlSerializer ifXml = new XmlSerializer(typeof(List<InputFile>));
ifXml.Serialize(w, InputFiles, ns);
//More serialization
}
Any ideas how to maintain the object type when I custom serialize the List?