Compartilhar via


XmlArrayAttribute Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Specifies that the XmlSerializer must serialize a particular class member as an array of XML elements.

Inheritance Hierarchy

System.Object
  System.Attribute
    System.Xml.Serialization.XmlArrayAttribute

Namespace:  System.Xml.Serialization
Assembly:  System.Xml (in System.Xml.dll)

Syntax

'Declaration
<AttributeUsageAttribute(AttributeTargets.Property Or AttributeTargets.Field Or AttributeTargets.Parameter Or AttributeTargets.ReturnValue, AllowMultiple := False)> _
Public Class XmlArrayAttribute _
    Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.ReturnValue, AllowMultiple = false)]
public class XmlArrayAttribute : Attribute

The XmlArrayAttribute type exposes the following members.

Constructors

  Name Description
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 XmlArrayAttribute() Initializes a new instance of the XmlArrayAttribute class.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 XmlArrayAttribute(String) Initializes a new instance of the XmlArrayAttribute class and specifies the XML element name generated in the XML document instance.

Top

Properties

  Name Description
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 ElementName Gets or sets the XML element name given to the serialized array.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 Form Gets or sets a value that indicates whether the XML element name generated by the XmlSerializer is qualified or unqualified.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 IsNullable Gets or sets a value that indicates whether the XmlSerializer must serialize a member as an empty XML element with the xsi:nil attribute set to true.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 Namespace Gets or sets the namespace of the XML element.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 Order Gets or sets the explicit order in which the elements are serialized or deserialized.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Equals Infrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetHashCode Returns the hash code for this instance. (Inherited from Attribute.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetType Gets the Type of the current instance. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Match When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

The XmlArrayAttribute belongs to a family of attributes that controls how the XmlSerializer serializes or deserializes an object.

You can apply the XmlArrayAttribute to a public field or read/write property that returns an array of objects, a collection, or any class that implements the IEnumerable interface.

When you apply the XmlArrayAttribute to a class member, the Serialize method of the XmlSerializer class generates a nested sequence of XML elements from that member. An XML schema document (an .xsd file) indicates such an array as a complexType. For example, if the class to be serialized represents a purchase order, you can generate an array of purchased items by applying the XmlArrayAttribute to a public field that returns an array of objects that represent order items.

If no attributes are applied to a public field or property that returns an array of complex or primitive type objects, the XmlSerializer generates a nested sequence of XML elements by default. To more precisely control what XML elements are generated, apply an XmlArrayItemAttribute and an XmlArrayAttribute to the field or property. For example, by default, the name of the generated XML element is derived from the member identifier. You can change the name of the generated XML element by setting the ElementName property.

If you serialize an array that contains items of a specific type and all the classes derived from that type, you must use the XmlArrayItemAttribute to declare each of the types.

NoteNote:

You can use XmlArray in your code instead of the longer XmlArrayAttribute.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.