System.Xml.Serialization.XmlArrayItemAttribute Class

Represents an attribute that specifies the derived types that the System.Xml.Serialization.XmlSerializer can place in a serialized array.

See Also: XmlArrayItemAttribute Members

Syntax

[System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.ReturnValue | System.AttributeTargets.All, AllowMultiple=true)]
public class XmlArrayItemAttribute : Attribute

Remarks

The System.Xml.Serialization.XmlArrayItemAttribute belongs to a family of attributes that controls how the System.Xml.Serialization.XmlSerializer serializes or deserializes an object. For a complete list of similar attributes, see Attributes That Control XML Serialization.

You can apply the System.Xml.Serialization.XmlArrayItemAttribute to any public read/write member that returns an array, or provides access to one. For example, a field that returns an array of objects, a collection, an ArrayList, or any class that implements the IEnumerable interface.

The System.Xml.Serialization.XmlArrayItemAttribute supports polymorphism--in other words, it allows the System.Xml.Serialization.XmlSerializer to add derived objects to an array. For example, suppose a class named Mammal is derived from a base class named Animal. Further suppose that a class named MyAnimals contains a field that returns an array of Animal objects. To allow the System.Xml.Serialization.XmlSerializer to serialize both the Animal and Mammal type, apply the System.Xml.Serialization.XmlArrayItemAttribute to the field twice, each time specifying one of the two acceptable types.

Note:

You can apply multiple instances of the System.Xml.Serialization.XmlArrayItemAttribute or System.Xml.Serialization.XmlElementAttribute to specify types of objects that can be inserted into the array.

Note:

The serialization of a field or property that returns an interface or array of interfaces is not supported.

For more information about using attributes, see Extending Metadata Using Attributes.

Note:

You can use the word XmlArrayItem in your code instead of the longer System.Xml.Serialization.XmlArrayItemAttribute.

Requirements

Namespace: System.Xml.Serialization
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0