Let’s say we have a class Root that contains an array of an abstract class BaseClass that is implemented by 2 derived classes Derived1 and Derived2
[XmlRootAttribute("root")]
public class Root
{
[XmlElement("derived1", typeof(Derived1))]
//[XmlElement("derived2", typeof(Derived2))]
public BaseClass[];
}
public abstract class BaseClass { }
public class Derived1 : BaseClass { }
public class Derived2 : BaseClass { }
How can i tell the XmlSerializer that instances of Derived2 should be ignored during serialization?
Thanks in advance!
I was wrong, there is: ShouldSerialize does the magic MSDN
Assuming your property is “Obj”
Edit:
If you want to take care of the serialization, you can implement IXmlSerializable interface as you said like this
This way you can take care of the serialization.
Note: The
GetSchema()is supposed to return null