views:

49

answers:

1

I have the following object graph:

public class BaseType
{
}

public class DerivedType : BaseType
{
}

When I pass DerivedType to XmlSerializer 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?

A: 

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...

nitzmahone