If using custom XML Serialization (IXmlSerialiable), on a complex object that contains properties with constituent complex objects which do NOT use custom IXmlSerializable interface, how do you specify, in the IXmlSerializable.ReadXml(XmlReader reader) method, that you want the deserializer to use the ordinary deserialization on those child properties?
NOTE: similar to this question
The
IXmlSerializableis a bit tedious to implement since it’s pretty much an all or nothing approach given that you cannot select child types for normal XML serialization. However, if I understood you correctly you can achieve what you want by manually creatingXmlSerializerfor the types that do not implementIXmlSerializable.For example, if we start with two classes,
Defaultthat does not implementIXmlSerializableandCustomwhich does implement it.Then we create a third class
Parentthat has a child of each of the previous instances and implementsIXmlSerializablein a way that callsReadXml/WriteXmlmethods for the child that supports it and create default XML serializer for the other child.To make the example complete, a sample program that serializes and deserializes a
Parentinstance: