Skip to main content

Definition

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

Syntax

Summary

Specifies that a member is serialized as an XML attribute. This class cannot be inherited.

Usage

Apply [XmlAttribute] to a property or field to write it as an XML attribute of the element that represents the object, instead of as a child element. Pass a name to the constructor to name the attribute, and set Namespace to put it in a namespace.
The code produces the following output:
View the complete sample on GitHub To write every simple member as an attribute without annotating each one, set XmlSerializerOptions.DefaultPropertyMapping to XmlPropertyMapping.Attribute.

Remarks

The member must have a simple type: a type with a built-in value converter, an enumeration, or the nullable form of either. A member of any other type cannot be serialized as an XML attribute.

Considerations

  • Only a simple value can be an XML attribute: a string, a number, a Boolean, a date or time, a GUID, a URI, an enumeration, and the nullable forms of those. On a member of any other type, such as an object or a collection, the serializer throws a NotSupportedException the first time the type is used.
  • A null value is left out. An attribute can’t be marked nil.
  • Attributes are written before element text and child elements. Among themselves they follow declaration order, or [XmlPropertyOrder] when it is set.
  • [XmlPropertyName] on the same member takes precedence over AttributeName. When neither is set, the member name is converted by AttributeNamingPolicy, or by PropertyNamingPolicy when that is null.
  • [XmlAttribute] can’t be combined with [XmlElement], [XmlText], or [XmlCData] on one member.
  • Characters that aren’t allowed in an attribute value, such as ", <, and &, are escaped when written and restored when read.

Constructors

.ctor

Initializes a new instance of the XmlAttributeAttribute class that uses the member name as the attribute name.

Syntax

.ctor

Initializes a new instance of the XmlAttributeAttribute class with the specified attribute name.

Syntax

Parameters

Exceptions

.ctor

Initializes a new instance of the XmlAttributeAttribute class with the specified attribute name and namespace.

Syntax

Parameters

Exceptions

.ctor Inherited

Inherited from System.Attribute

Syntax

.ctor Inherited

Inherited from object

Syntax

Properties

AttributeName

Gets or sets the local name of the XML attribute.

Syntax

Property Value

Type: string? The local name of the XML attribute. If the value is null or empty, the member name is used, converted by the attribute 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 XML attribute.

Syntax

Property Value

Type: string? The namespace URI of the XML attribute, or null for no namespace. The default is null.

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.XmlPropertyMapping
  • CloudNimble.Text.Xml.XmlSerializerOptions
  • CloudNimble.Text.Xml.Serialization.XmlElementAttribute
  • CloudNimble.Text.Xml.Serialization.XmlTextAttribute
  • CloudNimble.Text.Xml.Serialization.XmlPropertyNameAttribute
  • CloudNimble.Text.Xml.Serialization.XmlPropertyOrderAttribute