Definition
Assembly: CloudNimble.XmlEssentials.dll Namespace: CloudNimble.Text.Xml.Serialization Inheritance: System.AttributeSyntax
Summary
Specifies compile-time source generator configuration when applied to XmlSerializerContext class declarations. This class cannot be inherited.Usage
Apply[XmlSourceGenerationOptions] to a source-generated context to set the options its Default instance uses and the mode the generator works in.
Default and of a context created with the parameterless constructor. A context created with new CamelCaseOrderXmlContext(options) uses the options you pass instead.
The attribute is the counterpart of JsonSourceGenerationOptionsAttribute in System.Text.Json. An attribute argument must be a constant, so naming policies are chosen with the XmlKnownNamingPolicy enumeration and not with an XmlNamingPolicy instance.
View the complete sample on GitHub
Remarks
The values are the default options of the generated context. They apply when the context is created without options. When the caller passes an XmlSerializerOptions instance to the constructor, as innew AppXmlContext(options), that instance is used as it is and takes precedence over this attribute.
The source generator reads XmlSourceGenerationOptionsAttribute.AttributeNamingPolicy, XmlSourceGenerationOptionsAttribute.DefaultIgnoreCondition,
XmlSourceGenerationOptionsAttribute.DefaultNamespace, XmlSourceGenerationOptionsAttribute.DefaultPropertyMapping, XmlSourceGenerationOptionsAttribute.ElementNamingPolicy,
XmlSourceGenerationOptionsAttribute.GenerationMode, XmlSourceGenerationOptionsAttribute.IncludeFields,
XmlSourceGenerationOptionsAttribute.OmitXmlDeclaration, XmlSourceGenerationOptionsAttribute.PreferredObjectCreationHandling, XmlSourceGenerationOptionsAttribute.PropertyNamingPolicy,
XmlSourceGenerationOptionsAttribute.RespectNullableAnnotations, XmlSourceGenerationOptionsAttribute.UnknownTypeHandling, and XmlSourceGenerationOptionsAttribute.WriteIndented.
It does not read the other properties.
This attribute is analogous to JsonSourceGenerationOptionsAttribute in System.Text.Json.
Considerations
- The generator acts on every property.
GenerationModechooses what is generated. Every other property is copied to the options ofDefault:WriteIndented,OmitXmlDeclaration,EmitByteOrderMark,XmlVersion,DefaultNamespace,PropertyNamingPolicy,ElementNamingPolicy,AttributeNamingPolicy,PropertyNameCaseInsensitive,IncludeFields,IgnoreReadOnlyFields,IgnoreReadOnlyProperties,DefaultIgnoreCondition,DefaultPropertyMapping,DefaultCollectionMapping,MemberOrder,EnumHandling,CharHandling,UtcOffsetHandling,MaxDepth,PreferredObjectCreationHandling,RespectNullableAnnotations, andUnknownTypeHandling. IgnoreReadOnlyFieldsandIgnoreReadOnlyPropertiesturn the write fast path off. The fast path writes every member it was compiled with, so with either of these the context writes from the metadata. The output is the same as the reflection resolver’s.- The write fast path is compiled for the attribute’s values. The naming policies,
DefaultPropertyMapping, andIncludeFieldsfix the names and the choice of members in the write fast path. When you pass options to the constructor that differ in one of them, the fast path isn’t used: a context in the default mode writes from the metadata and follows your options. - The output uses
Environment.NewLineand the default layout. The attribute has noNewLine,EmptyElementStyle,AttributeStyle, orAttributesPerLineproperty. Pass options to the constructor to choose the line ending, the form of an empty element, or the layout of attributes.
Constructors
.ctor
Syntax
.ctor Inherited
Inherited from
System.AttributeSyntax
.ctor Inherited
Inherited from
objectSyntax
Properties
AttributeNamingPolicy
Gets or sets the built-in naming policy that converts member names to XML attribute names.Syntax
Property Value
Type:CloudNimble.Text.Xml.Serialization.XmlKnownNamingPolicy
One of the enumeration values that specifies the naming policy for attributes. The default is XmlKnownNamingPolicy.Unspecified.
CharHandling
Gets or sets how a Char is written and read: the character, or its number.Syntax
Property Value
Type:CloudNimble.Text.Xml.XmlCharHandling
One of the enumeration values. The default is XmlCharHandling.Character.
DefaultCollectionMapping
Gets or sets the default mapping of a collection member that has no mapping attribute: repeated elements, or a wrapper element.Syntax
Property Value
Type:CloudNimble.Text.Xml.XmlCollectionMapping
One of the enumeration values that specifies the default mapping of collection members. The default is
XmlCollectionMapping.Unwrapped.
DefaultIgnoreCondition
Gets or sets the default condition that determines when members are ignored.Syntax
Property Value
Type:CloudNimble.Text.Xml.Serialization.XmlIgnoreCondition
One of the enumeration values that specifies when members are ignored. The default is XmlIgnoreCondition.Never.
DefaultNamespace
Gets or sets the default namespace URI of the document element.Syntax
Property Value
Type:string?
The default namespace URI, or null for no namespace. The default is null.
DefaultPropertyMapping
Gets or sets the default mapping of a member that has no mapping attribute: a child element or an XML attribute.Syntax
Property Value
Type:CloudNimble.Text.Xml.XmlPropertyMapping
One of the enumeration values that specifies the default mapping of members. The default is XmlPropertyMapping.Element.
ElementNamingPolicy
Gets or sets the built-in naming policy that converts type and member names to XML element names.Syntax
Property Value
Type:CloudNimble.Text.Xml.Serialization.XmlKnownNamingPolicy
One of the enumeration values that specifies the naming policy for elements. The default is XmlKnownNamingPolicy.Unspecified.
EmitByteOrderMark
Gets or sets a value that indicates whether a UTF-8 byte order mark is written.Syntax
Property Value
Type:bool
true if a UTF-8 byte order mark is written; otherwise, false. The default is false.
EnumHandling
Gets or sets how enumeration values are written.Syntax
Property Value
Type:CloudNimble.Text.Xml.XmlEnumHandling
One of the enumeration values that specifies how enumeration values are written. The default is XmlEnumHandling.Name.
GenerationMode
Gets or sets the source generation mode for the types of the context.Syntax
Property Value
Type:CloudNimble.Text.Xml.Serialization.XmlSourceGenerationMode
A bitwise combination of the enumeration values that specifies what the source generator generates. The default is
XmlSourceGenerationMode.Default, which generates both type metadata and serialization logic.
Remarks
XmlSerializableAttribute`1.GenerationMode overrides this value for the type it lists.IgnoreReadOnlyFields
Gets or sets a value that indicates whether read-only fields are ignored.Syntax
Property Value
Type:bool
true if read-only fields are ignored; otherwise, false. The default is false.
IgnoreReadOnlyProperties
Gets or sets a value that indicates whether read-only properties are ignored.Syntax
Property Value
Type:bool
true if read-only properties are ignored; otherwise, false. The default is false.
IncludeFields
Gets or sets a value that indicates whether fields are serialized and deserialized.Syntax
Property Value
Type:bool
true if public fields are serialized and deserialized; otherwise, false. The default is false.
MaxDepth
Gets or sets the maximum depth of nested elements.Syntax
Property Value
Type:int
The maximum element depth. A value of 0 selects the default limit. The default is 0.
MemberOrder
Gets or sets where the fields of a type come among its members: after its properties, or before them.Syntax
Property Value
Type:CloudNimble.Text.Xml.XmlMemberOrder
One of the enumeration values. The default is XmlMemberOrder.PropertiesFirst.
OmitXmlDeclaration
Gets or sets a value that indicates whether the XML declaration is omitted.Syntax
Property Value
Type:bool
true if the XML declaration is omitted; otherwise, false. The default is false.
PreferredObjectCreationHandling
Gets or sets whether a member that already holds a value is given a new one or has its value populated when it is read.Syntax
Property Value
Type:CloudNimble.Text.Xml.Serialization.XmlObjectCreationHandling
One of the enumeration values. The default is XmlObjectCreationHandling.Replace.
PropertyNameCaseInsensitive
Gets or sets a value that indicates whether element and attribute names are matched to members without regard to case on deserialization.Syntax
Property Value
Type:bool
true if names are compared without regard to case; otherwise, false. The default is false.
PropertyNamingPolicy
Gets or sets the built-in naming policy that converts names to XML names when XmlSourceGenerationOptionsAttribute.ElementNamingPolicy or XmlSourceGenerationOptionsAttribute.AttributeNamingPolicy is not set.Syntax
Property Value
Type:CloudNimble.Text.Xml.Serialization.XmlKnownNamingPolicy
One of the enumeration values that specifies the naming policy for members. The default is XmlKnownNamingPolicy.Unspecified.
RespectNullableAnnotations
Gets or sets a value that indicates whether anull is refused for a member or constructor parameter annotated non-nullable.
Syntax
Property Value
Type:bool
true if nullable annotations are respected; otherwise, false. The default is false.
TypeId Inherited Virtual
Inherited from
System.AttributeSyntax
Property Value
Type:object
UnknownTypeHandling
Gets or sets what an element is read as when the declared type is Object.Syntax
Property Value
Type:CloudNimble.Text.Xml.Serialization.XmlUnknownTypeHandling
One of the enumeration values. The default is XmlUnknownTypeHandling.XmlElement.
UtcOffsetHandling
Gets or sets how a DateTimeOffset whose offset is zero is written:+00:00 or Z.
Syntax
Property Value
Type:CloudNimble.Text.Xml.XmlUtcOffsetHandling
One of the enumeration values. The default is XmlUtcOffsetHandling.WriteOffset.
WriteIndented
Gets or sets a value that indicates whether the output is indented.Syntax
Property Value
Type:bool
true if the output is indented; otherwise, false. The default is false.
XmlVersion
Gets or sets the XML version that is written in the XML declaration.Syntax
Property Value
Type:CloudNimble.Text.Xml.XmlVersion
One of the enumeration values that specifies the XML version. The default is XmlVersion.Version10.
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.XmlSerializerContext
- CloudNimble.Text.Xml.Serialization.XmlSerializableAttribute
- CloudNimble.Text.Xml.Serialization.XmlSourceGenerationMode
- CloudNimble.Text.Xml.Serialization.XmlKnownNamingPolicy
- CloudNimble.Text.Xml.XmlSerializerOptions