Definition
Assembly: CloudNimble.XmlEssentials.dll Namespace: CloudNimble.Text.Xml.Serialization Inheritance: CloudNimble.Text.Xml.Serialization.XmlConverterAttributeSyntax
Summary
Specifies the converter type to use when placed on a property, field, or type. This class cannot be inherited.Usage
Apply[XmlConverter] to a class, struct, or enumeration to name the converter the serializer uses for it. Every XmlSerializerOptions instance then uses that converter, with nothing to register. Apply it to a property or field instead to convert that one member.
XmlConverter<T> or XmlConverterFactory and have a public parameterless constructor. The attribute is the counterpart of JsonConverterAttribute in System.Text.Json.
View the complete sample on GitHub
Remarks
On a type, the converter reads and writes every value of the type, unless XmlSerializerOptions.Converters holds a converter for it. On a property or field, the converter reads and writes that member only, and comes before both. It handles the whole value of the member: a collection is not taken apart into items, the member may be an attribute or text, and a converter forT serves a member of type T?. A source-generated context applies
the attribute on a type and on a member, as the reflection resolver does. The converter is a type argument, so the
compiler checks that it is a converter and can be created, and no reflection is needed to create it.
Type Parameters
TConverter- The type of the converter. It derives from XmlConverter and has a public parameterless constructor.
Examples
Considerations
- On a property or field, the converter serves that member only. It reads and writes the whole value of the member, as
[JsonConverter]does in System.Text.Json: a collection isn’t taken apart into items, the member may be an attribute or text, and a converter forTserves a member of typeT?. A member attribute comes beforeXmlSerializerOptions.Convertersand before an attribute on the type. - A converter in the options wins over the attribute on a type.
XmlSerializerOptions.Convertersis searched before the attribute on the type, so a caller can override the converter a type names. It doesn’t override an attribute on a member. - One instance for each options instance. The serializer creates the converter the first time the options need it and keeps it. A converter named on a property or field is created once for that member.
- The converter is a type argument.
[XmlConverter<MoneyConverter>]names the converter, and the compiler checks that it derives fromXmlConverterand has a public parameterless constructor. A converter that can’t convert the annotated type still fails at run time: the serializer throwsInvalidOperationExceptionwhen it first needs it. - Source generation reads the attribute on a type and on a member. A generated context reads and writes a type that carries
[XmlConverter]with that converter, in place of generated metadata for the type. On a property or field, the attribute is carried in the generated metadata, and the converter reads and writes that member. - The converter is created without reflection. The converter type is a type argument with a
new()constraint, so the attribute creates it directly and trimming and Native AOT need nothing extra.
Constructors
.ctor
Syntax
.ctor Inherited
Inherited from
CloudNimble.Text.Xml.Serialization.XmlConverterAttributeSyntax
Remarks
OnlyXmlConverterAttribute1` derives from this class: a class outside this library cannot.
.ctor Inherited
Inherited from
System.AttributeSyntax
.ctor Inherited
Inherited from
objectSyntax
Properties
ConverterType Override
Syntax
Property Value
Type:System.Type
ConverterType Inherited Abstract
Inherited from
CloudNimble.Text.Xml.Serialization.XmlConverterAttributeSyntax
Property Value
Type:System.Type
The type of the converter, which derives from XmlConverter.
TypeId Inherited Virtual
Inherited from
System.AttributeSyntax
Property Value
Type:object
Methods
CreateConverter Inherited Abstract
Inherited from
CloudNimble.Text.Xml.Serialization.XmlConverterAttributeSyntax
Returns
Type:CloudNimble.Text.Xml.Serialization.XmlConverter
A new converter.
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.XmlConverter
- CloudNimble.Text.Xml.Serialization.XmlConverterFactory
- CloudNimble.Text.Xml.XmlSerializerOptions