I have class A
inherits from class B
. I have a list of class B
that contains A
and B
items:
List<B> myList = new List<B>();
myList.Add(new A());
When I try to serialize this list using XmlSerializable
, an exception is thrown. If I define the list to of type B, then I do not get this exception. What is the best way to serialize the derived class?
XmlIncludeAttribute will do the trick.
If you go to this url, you will find a code sample there too.
Also, in the example the attribute is applied to the method, but you might want to apply it class A in your case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With