XmlInclude
XmlInclude is an attribute in the System.Xml.Serialization namespace used to inform the XmlSerializer about additional types that may appear when serializing or deserializing objects declared as a base type. It enables proper handling of polymorphism by listing derived types that could be encountered through a base-type reference.
The attribute is applied to a base class (or interface). You can place multiple XmlInclude attributes on
using System.Xml.Serialization;
{
public string Name { get; set; }
}
{
public int Lives { get; set; }
}
{
public string Breed { get; set; }
}
In this example, a property of type Pet or a collection of Pet can contain Cat or
Notes and limitations: XmlInclude only affects the XmlSerializer and is relevant for polymorphic scenarios involving base-type