Definition
Assembly: CloudNimble.XmlEssentials.dll Namespace: CloudNimble.Text.Xml.Serialization Inheritance: System.AttributeSyntax
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.
[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>.
Empty and null collections
A wrapper can show the difference between an empty collection and anull one. Repeated elements with no wrapper can’t. Playlist.Tracks in the following example has no [XmlArray].
Considerations
System.Xml.Serialization.XmlSerializerwraps collections by default. This serializer doesn’t, so add[XmlArray]when you need XML that matches what that serializer produced, or setXmlSerializerOptions.DefaultCollectionMappingtoXmlCollectionMapping.Wrappedto wrap every collection member that has no mapping attribute.- The default item name is the one
System.Xml.Serializationuses: the XML Schema name of a built-in type, such asint,string,boolean, ordateTime, 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 overElementName, and[XmlPropertyOrder]and[XmlElement(Order = n)]take precedence overOrder.- A
nullwrapped collection is written as the wrapper markedxsi:nil="true". It is left out when the ignore condition that applies to the member isWhenWritingNull,WhenWritingNullReference, orWhenWritingDefault. - 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.AttributeSyntax
.ctor Inherited
Inherited from
objectSyntax
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.AttributeSyntax
Property Value
Type:object
Methods
Equals Override
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
Equals Inherited Virtual
Inherited from
objectSyntax
Parameters
Returns
Type:bool
Equals Inherited
Inherited from
objectSyntax
Parameters
Returns
Type:bool
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetHashCode Override
Inherited from
System.AttributeSyntax
Returns
Type:int
GetHashCode Inherited Virtual
Inherited from
objectSyntax
Returns
Type:int
GetType Inherited
Inherited from
objectSyntax
Returns
Type:System.Type
IsDefaultAttribute Inherited Virtual
Inherited from
System.AttributeSyntax
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
Match Inherited Virtual
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
MemberwiseClone Inherited
Inherited from
objectSyntax
Returns
Type:object
ReferenceEquals Inherited
Inherited from
objectSyntax
Parameters
Returns
Type:bool
ToString Inherited Virtual
Inherited from
objectSyntax
Returns
Type:string?
Related APIs
- CloudNimble.Text.Xml.Serialization.XmlArrayItemAttribute
- CloudNimble.Text.Xml.Serialization.XmlElementAttribute
- CloudNimble.Text.Xml.Serialization.XmlPropertyNameAttribute
- CloudNimble.Text.Xml.Serialization.XmlPropertyOrderAttribute