Skip to main content

Definition

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

Syntax

Summary

Specifies the local name of the XML element or attribute that a property or field is serialized as. This class cannot be inherited.

Usage

Apply [XmlPropertyName] to a property or field to set its XML name. It is the counterpart of [JsonPropertyName], and it works whether the member is written as an element or as an XML attribute. On an enumeration member, it sets the name the value is written as.
In the following type, Name is written as the title element.
Serializing a CatalogItem with these attributes produces the following XML:
View the complete sample on GitHub

Remarks

The name overrides any naming policy, and takes precedence over the name set by XmlElementAttribute, XmlAttributeAttribute, or XmlArrayAttribute on the same member. This attribute is analogous to JsonPropertyNameAttribute in System.Text.Json. On a member of an enumeration, the name is the text the member is written as and read from, as JsonStringEnumMemberNameAttribute is in System.Text.Json. It replaces the C# name and is matched exactly, while a C# name is matched without regard to case. A name cannot start or end with white space, and the name of a FlagsAttribute member cannot contain any.

Considerations

  • The name takes precedence over a name set in [XmlElement], [XmlAttribute], or [XmlArray] on the same member, and a naming policy doesn’t convert it.
  • The attribute sets the local name only. To set a namespace, use the Namespace property of [XmlElement], [XmlAttribute], or [XmlArray].
  • On a collection with no [XmlArray], the name applies to each repeated item. With [XmlArray], it names the wrapper element.
  • Two members of one type can’t have the same attribute name, and two element members can’t have the same element name in the same namespace. The serializer throws an InvalidOperationException the first time it uses such a type.
  • On an enumeration member, the attribute sets the name the value is written as, such as [XmlPropertyName("next-day")] on NextDay. When reading, that name is matched exactly, while the other member names are matched in any case. See Enumeration values.

Constructors

.ctor

Initializes a new instance of the XmlPropertyNameAttribute class with the specified name.

Syntax

Parameters

Exceptions

.ctor Inherited

Inherited from System.Attribute

Syntax

.ctor Inherited

Inherited from object

Syntax

Properties

Name

Gets the local name of the XML element or attribute.

Syntax

Property Value

Type: string The local name of the XML element or attribute.

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.XmlNamingPolicy
  • CloudNimble.Text.Xml.Serialization.XmlElementAttribute
  • CloudNimble.Text.Xml.Serialization.XmlAttributeAttribute
  • CloudNimble.Text.Xml.Serialization.XmlRootAttribute
  • CloudNimble.Text.Xml.Serialization.XmlPropertyOrderAttribute