Skip to main content

Definition

Assembly: CloudNimble.XmlEssentials.dll Namespace: CloudNimble.Text.Xml.Serialization Inheritance: System.Attribute

Syntax

Summary

Specifies that a collection member is serialized as a wrapper element that contains the items. This class cannot be inherited.

Usage

Apply [XmlArray] to a collection property or field to write its items inside one wrapper element. Without the attribute, the items are written as repeated elements named after the member, with no wrapper. Pair it with [XmlArrayItem] to name the items.
The code produces the following output:
View the complete sample on GitHub The name is optional. [XmlArray] with no arguments uses the member name for the wrapper.

Remarks

Without this attribute, the items are written as repeated elements that use the member’s element name, with no wrapper.

Examples

The following examples show the names and the shapes that a wrapped collection produces.

Default item names

Without [XmlArrayItem], each item of a wrapped collection is named after its type. A built-in type has its XML Schema name, so an int item is <int>.
The code produces the following output:

Empty and null collections

A wrapper can show the difference between an empty collection and a null one. Repeated elements with no wrapper can’t. Playlist.Tracks in the following example has no [XmlArray].
The code produces the following output:
View the complete sample on GitHub

Considerations

  • System.Xml.Serialization.XmlSerializer wraps collections by default. This serializer doesn’t, so add [XmlArray] when you need XML that matches what that serializer produced, or set XmlSerializerOptions.DefaultCollectionMapping to XmlCollectionMapping.Wrapped to wrap every collection member that has no mapping attribute.
  • The default item name is the one System.Xml.Serialization uses: the XML Schema name of a built-in type, such as int, string, boolean, or dateTime, and the name of the type otherwise, such as the name of your class. A name that comes from the type, not from [XmlRoot], is converted by the element naming policy.
  • [XmlPropertyName] on the same member takes precedence over ElementName, and [XmlPropertyOrder] and [XmlElement(Order = n)] take precedence over Order.
  • A null wrapped collection is written as the wrapper marked xsi:nil="true". It is left out when the ignore condition that applies to the member is WhenWritingNull, WhenWritingNullReference, or WhenWritingDefault.
  • The attribute applies to collections. A dictionary is always written inside an element named after the member, without it.

Constructors

.ctor

Initializes a new instance of the XmlArrayAttribute class that uses the member name as the wrapper element name.

Syntax

.ctor

Initializes a new instance of the XmlArrayAttribute class with the specified wrapper element name.

Syntax

Parameters

Exceptions

.ctor Inherited

Inherited from System.Attribute

Syntax

.ctor Inherited

Inherited from object

Syntax

Properties

ElementName

Gets or sets the local name of the wrapper element.

Syntax

Property Value

Type: string? The local name of the wrapper element. If the value is null or empty, the member name is used, converted by the element naming policy. The default is null.

Remarks

An XmlPropertyNameAttribute on the same member takes precedence over this property.

Namespace

Gets or sets the namespace URI of the wrapper element.

Syntax

Property Value

Type: string? The namespace URI of the wrapper element. If the value is null, the namespace set by an XmlElementAttribute on the same member is used, and without one the wrapper element is written with an unqualified name. An empty string puts the wrapper element in no namespace. The default is null.

Order

Gets or sets the order of the wrapper element among the child elements of the containing type.

Syntax

Property Value

Type: int The order of the wrapper element. Lower values are written first. A negative value means the order is not set. The default is -1.

Remarks

The value is used only when neither an XmlPropertyOrderAttribute nor an XmlElementAttribute.Order on the same member sets an order.

TypeId Inherited Virtual

Inherited from System.Attribute

Syntax

Property Value

Type: object

Methods

Equals Override

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

Equals Inherited Virtual

Inherited from object

Syntax

Parameters

Returns

Type: bool

Equals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetHashCode Override

Inherited from System.Attribute

Syntax

Returns

Type: int

GetHashCode Inherited Virtual

Inherited from object

Syntax

Returns

Type: int

GetType Inherited

Inherited from object

Syntax

Returns

Type: System.Type

IsDefaultAttribute Inherited Virtual

Inherited from System.Attribute

Syntax

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

Match Inherited Virtual

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

MemberwiseClone Inherited

Inherited from object

Syntax

Returns

Type: object

ReferenceEquals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

ToString Inherited Virtual

Inherited from object

Syntax

Returns

Type: string?
  • CloudNimble.Text.Xml.Serialization.XmlArrayItemAttribute
  • CloudNimble.Text.Xml.Serialization.XmlElementAttribute
  • CloudNimble.Text.Xml.Serialization.XmlPropertyNameAttribute
  • CloudNimble.Text.Xml.Serialization.XmlPropertyOrderAttribute