Definition
Assembly: CloudNimble.XmlEssentials.dll Namespace: CloudNimble.Text.Xml.Serialization Inheritance: System.AttributeSyntax
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.
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
NotSupportedExceptionthe first time the type is used. - A
nullvalue 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 overAttributeName. When neither is set, the member name is converted byAttributeNamingPolicy, or byPropertyNamingPolicywhen that isnull.[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.AttributeSyntax
.ctor Inherited
Inherited from
objectSyntax
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.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.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