Different options for XmlSerialization and derived type
I have the following object graph:
public class BaseType
{
}
public class DerivedType : BaseType
{
}
When I pass DerivedType to XmlSeria开发者_C百科lizer I need to have it reflect on BaseType instead of DerivedType. Is there a way to control this with attributes without implementing IXmlSerializer on DerivedType?
If you have control over the serializer instancing, just pass a Type[] with the derived type object as extraTypes. Otherwise, add an
[XmlInclude(typeof(Derived))]
to the base class definition. The output XML will look exactly the same as if you'd passed a base instance except the xsi:type attribute with the derived type name.
I think this is what you were asking for...
精彩评论