Skip to main content

Definition

Assembly: CloudNimble.XmlEssentials.dll Namespace: CloudNimble.Text.Xml

Syntax

Summary

Provides options to be used with XmlSerializer. This class cannot be inherited.

Usage

XmlSerializerOptions holds the settings that control how XmlSerializer writes and reads XML: names, indentation, null handling, limits, converters, and where type metadata comes from. It is the counterpart of JsonSerializerOptions. Create an instance once, set its properties in the initializer, and pass the same instance to every call:
The code produces the following output:
There are three ways to get an instance:
  • new XmlSerializerOptions() for the general defaults, or new XmlSerializerOptions(XmlSerializerDefaults.Web), XmlSerializerDefaults.Strict, or XmlSerializerDefaults.Bcl for the other three sets.
  • new XmlSerializerOptions(existing) to copy an instance and change the copy.
  • The shared, read-only instances XmlSerializerOptions.Default, XmlSerializerOptions.Web, XmlSerializerOptions.Strict, and XmlSerializerOptions.Bcl.
An instance becomes read-only the first time it is used, or when you call MakeReadOnly. Every option, with its default, is listed in Configure XmlSerializerOptions.

Remarks

This class is the XML counterpart of System.Text.Json.JsonSerializerOptions. An instance becomes read-only the first time it is used to serialize or deserialize, or when XmlSerializerOptions.MakeReadOnly is called. Create one instance and reuse it: the converters and type info it resolves are cached on the instance.

Examples

The following examples show the three ways to get an options instance and what happens once an instance is in use.

Use the built-in instances

The code produces the following output:

Start from a set of defaults and copy an instance

The code produces the following output:

See when an instance becomes read-only

The code produces the following output:
View the complete sample on GitHub

Best Practices

  • Create options once. Keep each instance in a static readonly field or a singleton. Never create one per call: the type metadata is cached on the instance, and a new instance starts with none.
  • Set everything in the initializer. An instance can’t be changed after its first use, so finish configuring it where you create it.
  • Use the same instance to read and to write. Naming policies, the default property mapping, and the default namespace change the names the serializer looks for when it reads.
  • Call MakeReadOnly before you share an instance with code that might otherwise change it before its first use.
  • Copy at startup, not per call. A copy shares none of the source’s cached metadata.
  • Set NewLine when the output must be identical on every operating system. Its default is Environment.NewLine, and it is written for every line break: the ones WriteIndented adds and the ones inside values. It accepts "\n" and "\r\n".
  • Set the layout options to match the files you already have. EmptyElementStyle chooses between <e/>, <e /> and <e></e>, and AttributeStyle with AttributesPerLine chooses how the attributes of a start tag are laid out. They change how the output looks, not what a reader gets from it, and they are passed to the writer under the same names.
  • Start from XmlSerializerOptions.Strict for XML you don’t control, and set MaxDocumentByteCount. See Security.

Considerations

An options instance carries a cache as well as settings, which explains most of what follows.

Read-only after first use

Serializing, deserializing, or calling GetTypeInfo or TryGetTypeInfo makes the instance read-only. From then on every setter throws an InvalidOperationException with the message This XmlSerializerOptions instance is read-only., and so do changes to Converters and TypeInfoResolverChain. The four static instances are read-only from the start. To change a read-only instance, copy it with new XmlSerializerOptions(existing).

The resolver is given, not assumed

TypeInfoResolver is null on a new instance. GetTypeInfo and TryGetTypeInfo use the resolver the instance has, and throw an InvalidOperationException when it has none. The members that need reflection give an instance without a resolver the reflection resolver: every XmlSerializer method that takes options, GetConverter, MakeReadOnly(populateMissingResolver: true), and the four static instances. Each of them carries RequiresUnreferencedCode and RequiresDynamicCode, so a trimmed or Native AOT application gets a warning where it uses one. A copy made with new XmlSerializerOptions(existing) keeps a resolver you set, and not one that was only given: a copy of XmlSerializerOptions.Web has none, so a context you create from it becomes its resolver.

The cache lives on the instance

Each instance caches the converter and the type metadata for every type it has been used with. A call with a new instance builds that metadata again, which costs many times what the call itself costs. See Benchmarks. The cache is never trimmed, so an application that keeps creating instances also keeps their metadata alive for as long as it holds them.

Zero means the built-in default

IndentSize, DefaultBufferSize, and the Max* limits are 0 on a new instance. For each of them, 0 selects the built-in value: an indent of 2, a 16,384-byte buffer, a depth of 64, 1,000 attributes, 1,024 bytes for a name, 16,777,216 bytes for a text value, and 1,048,576 bytes for a comment. MaxDocumentByteCount is the exception: 0 means no limit.

Closed types

InferClosedTypePolymorphism takes the derived types of a closed type from the list the compiler makes, for a type that declares none with [XmlDerivedType<T>]. It is false by default, as in System.Text.Json. A closed type needs C# 15 and .NET 11. See Infer the derived types of a closed type.

Differences from JsonSerializerOptions

  • XmlSerializerDefaults.Web sets only PropertyNamingPolicy to camelCase and OmitXmlDeclaration to true. It doesn’t turn on case-insensitive matching.
  • RespectRequiredConstructorParameters defaults to true.
  • There are three naming policies for members instead of one: PropertyNamingPolicy, and ElementNamingPolicy and AttributeNamingPolicy, which override it for their kind of name.
  • XML has options that JSON has no use for, such as DefaultPropertyMapping, DefaultNamespace, OmitXmlDeclaration, and XmlVersion.

Thread safety

A read-only instance is meant to be shared between threads. See Thread safety.

Constructors

.ctor

Initializes a new instance of the XmlSerializerOptions class.

Syntax

Remarks

The new instance uses the XmlSerializerDefaults.General configuration.

.ctor

Initializes a new instance of the XmlSerializerOptions class with a predefined set of options determined by the specified XmlSerializerDefaults.

Syntax

Parameters

.ctor

Initializes a new instance of the XmlSerializerOptions class by copying the options from another instance.

Syntax

Parameters

Exceptions

Remarks

The copy is not read-only and shares no cached state with options.

.ctor Inherited

Inherited from object

Syntax

Properties

AllowDuplicateProperties

Gets or sets a value that indicates whether a property can appear more than once in an object being deserialized.

Syntax

Property Value

Type: bool true if duplicate properties are allowed; false to throw an XmlException when a property appears a second time. The default is true.

Exceptions

AttributeNamingPolicy

Gets or sets the policy used to convert a member’s name to an XML attribute name.

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlNamingPolicy? A naming policy for attribute names, or null to use XmlSerializerOptions.PropertyNamingPolicy. The default is null.

Exceptions

AttributesPerLine

Gets or sets the number of attributes written to a line when XmlSerializerOptions.AttributeStyle is XmlAttributeStyle.PerLine.

Syntax

Property Value

Type: int The number of attributes to a line. The default is 1. The value is not read when XmlSerializerOptions.AttributeStyle is XmlAttributeStyle.Inline.

Exceptions

AttributeStyle

Gets or sets a value that specifies how the attributes of a start tag are laid out.

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlAttributeStyle One of the enumeration values. The default is XmlAttributeStyle.Inline, which writes every attribute on the line of the start tag.

Exceptions

Remarks

The value is passed to the writer as XmlWriterOptions.AttributeStyle.

Bcl

Gets a read-only, singleton instance of XmlSerializerOptions that writes what System.Xml.Serialization.XmlSerializer writes.

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlSerializerOptions A read-only instance created with XmlSerializerDefaults.Bcl.

Examples

Remarks

Use it when the documents have to stay the ones the old serializer wrote, for a consumer that already reads them. It sets: To change one of them, create an instance with XmlSerializerOptions..ctor and XmlSerializerDefaults.Bcl, which is not read-only.

CharHandling

Gets or sets a value that specifies how a Char is written and read.

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlCharHandling One of the enumeration values that specifies whether a Char is the character or its number. The default is XmlCharHandling.Character.

Exceptions

Remarks

The value applies to an element, an attribute and an item of a collection alike. Under XmlCharHandling.Number a value that is not a number from 0 to 65535 is an error.

Converters

Gets the list of user-defined converters that were registered.

Syntax

Property Value

Type: System.Collections.Generic.IList<CloudNimble.Text.Xml.Serialization.XmlConverter> The list of custom converters.

Remarks

A converter in this list is used before an XmlConverterAttribute on the type and before the built-in converters. The list cannot be changed after this instance has become read-only.

Default

Gets a read-only, singleton instance of XmlSerializerOptions that uses the default configuration.

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlSerializerOptions A read-only instance created with XmlSerializerDefaults.General.

DefaultBufferSize

Gets or sets the default buffer size, in bytes, to use when creating temporary buffers.

Syntax

Property Value

Type: int The default buffer size, in bytes. The default is 0, which means 16,384.

Exceptions

Remarks

This is the size of the first buffer rented when serializing, and of the first read buffer of DeserializeAsyncEnumerable.

DefaultCollectionMapping

Gets or sets a value that specifies how collection members without a mapping attribute are mapped to XML.

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlCollectionMapping One of the enumeration values that specifies whether the items of an unannotated collection member are written as repeated elements or inside a wrapper element. The default is XmlCollectionMapping.Unwrapped.

Exceptions

Remarks

With XmlCollectionMapping.Wrapped, a collection member is written as [XmlArray] writes it: one element named for the member, with an element for each item named for the item’s type. An empty collection is an empty wrapper element. This is what System.Xml.Serialization.XmlSerializer does by default. [XmlElement] on a member writes its items with no wrapper under either value, and [XmlArray] writes a wrapper under either value. [XmlArrayItem] names the items of a wrapped collection, including one this property wraps. Dictionaries and byte[] are not collections for this purpose. The same value is used to read.

DefaultIgnoreCondition

Gets or sets a value that determines when members are ignored during serialization or deserialization.

Syntax

Property Value

Type: CloudNimble.Text.Xml.Serialization.XmlIgnoreCondition One of the enumeration values that specifies when a member is ignored. The default is XmlIgnoreCondition.Never.

Exceptions

Remarks

An XmlIgnoreAttribute on a member overrides this value for that member. Every value but XmlIgnoreCondition.Always is accepted. XmlIgnoreCondition.WhenWriting and XmlIgnoreCondition.WhenReading have no effect as the default for every member, as in System.Text.Json: they apply only where an XmlIgnoreAttribute gives them.

DefaultNamespace

Gets or sets the namespace URI of the document element for types that do not specify one.

Syntax

Property Value

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

Exceptions

Remarks

A namespace set on the type with XmlRootAttribute takes precedence over this value.

DefaultPropertyMapping

Gets or sets a value that specifies how members without a mapping attribute are mapped to XML.

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlPropertyMapping One of the enumeration values that specifies whether an unannotated member is written as a child element or as an attribute. The default is XmlPropertyMapping.Element.

Exceptions

Remarks

The default is XmlPropertyMapping.Element: public properties become child elements, matching JSON properties in System.Text.Json. Set XmlPropertyMapping.Attribute to write unannotated simple members as XML attributes without annotating each one. Nested objects and collections stay elements. [XmlElement], [XmlAttribute], and [XmlText] override this per member.

DictionaryKeyPolicy

Gets or sets the policy used to convert a dictionary key’s name to another format, such as camel-casing.

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlNamingPolicy? A naming policy for dictionary keys, or null to use XmlSerializerOptions.PropertyNamingPolicy. The default is null.

Exceptions

ElementNamingPolicy

Gets or sets the policy used to convert a type’s or member’s name to an XML element name.

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlNamingPolicy? A naming policy for element names, or null to use XmlSerializerOptions.PropertyNamingPolicy. The default is null.

Exceptions

EmitByteOrderMark

Gets or sets a value that indicates whether a UTF-8 byte order mark is written at the start of the output.

Syntax

Property Value

Type: bool true if a UTF-8 byte order mark is written; otherwise, false. The default is false.

Exceptions

EmptyElementStyle

Gets or sets a value that specifies how an element that has no content is written.

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlEmptyElementStyle One of the enumeration values. The default is XmlEmptyElementStyle.SelfClosing, which writes <e/>.

Exceptions

Remarks

The value is passed to the writer as XmlWriterOptions.EmptyElementStyle.

EnumHandling

Gets or sets a value that specifies how enumeration values are written.

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlEnumHandling One of the enumeration values that specifies whether an enumeration value is written as its member name or as its underlying integer. The default is XmlEnumHandling.Name.

Exceptions

IgnoreReadOnlyFields

Gets or sets a value that indicates whether read-only fields are ignored during serialization and deserialization.

Syntax

Property Value

Type: bool true if read-only fields are ignored; otherwise, false. The default is false.

Exceptions

Remarks

A field is read-only if it is declared readonly. Fields are considered only when XmlSerializerOptions.IncludeFields is true. A collection or a dictionary is not ignored.

IgnoreReadOnlyProperties

Gets or sets a value that indicates whether read-only properties are ignored during serialization and deserialization.

Syntax

Property Value

Type: bool true if read-only properties are ignored; otherwise, false. The default is false.

Exceptions

Remarks

A property is read-only if it has no set or init accessor. A collection or a dictionary is not ignored: it is written from its getter, and filled through it when XmlSerializerOptions.PreferredObjectCreationHandling is XmlObjectCreationHandling.Populate.

IncludeFields

Gets or sets a value that indicates whether public fields are handled during serialization and deserialization.

Syntax

Property Value

Type: bool true if public fields are included; otherwise, false. The default is false.

Exceptions

IndentCharacter

Gets or sets the indentation character used when XmlSerializerOptions.WriteIndented is true.

Syntax

Property Value

Type: char The indentation character. The default is the space character.

Exceptions

IndentSize

Gets or sets the indentation size used when XmlSerializerOptions.WriteIndented is true.

Syntax

Property Value

Type: int The number of XmlSerializerOptions.IndentCharacter characters written per nesting level. The default is 0, which means 2.

Exceptions

InferClosedTypePolymorphism

Gets or sets a value that indicates whether the derived types of a closed type are inferred.

Syntax

Property Value

Type: bool true if the derived types of a closed type that declares none are taken from its closed hierarchy; otherwise, false. The default is false.

Exceptions

Remarks

A closed type is a class declared with the closed modifier, which needs C# 15 and .NET 11. Its derived types are all in its own assembly, and the compiler lists them. A derived type is written and read as if the closed type had an XmlDerivedTypeAttribute for it, with the name of the derived type as its discriminator. XmlPolymorphicAttribute.InferClosedTypePolymorphism on a type takes precedence over this value, and a type that declares derived types with XmlDerivedTypeAttribute has nothing inferred. This is the counterpart of JsonSerializerOptions.InferClosedTypePolymorphism.

IsReadOnly

Gets a value that indicates whether the current instance has been locked for modification.

Syntax

Property Value

Type: bool true if this instance can no longer be changed; otherwise, false. The default is false.

MaxAttributeCount

Gets or sets the maximum number of attributes allowed on one element.

Syntax

Property Value

Type: int The maximum number of attributes on one element. The default is 0, which means 1000.

Exceptions

MaxCommentByteCount

Gets or sets the maximum size, in bytes, of the content of a comment that is read.

Syntax

Property Value

Type: int The maximum size of a comment’s content, in bytes. The default is 0, which means 1,048,576.

Exceptions

MaxDepth

Gets or sets the maximum depth allowed when serializing or deserializing XML.

Syntax

Property Value

Type: int The maximum element depth allowed when serializing or deserializing XML. The default is 0, which means 64.

Exceptions

MaxDocumentByteCount

Gets or sets the maximum size, in bytes, of a document that is read.

Syntax

Property Value

Type: int The maximum document size, in bytes. The default is 0, which means the size is not limited.

Exceptions

MaxNameByteCount

Gets or sets the maximum length, in bytes, of an XML name.

Syntax

Property Value

Type: int The maximum length of a name, in bytes. The default is 0, which means 1024.

Exceptions

MaxTextByteCount

Gets or sets the maximum size of a text node, a CDATA section, an attribute value, or the data of a processing instruction that is read.

Syntax

Property Value

Type: int The maximum size of each, in UTF-8 bytes as they appear in the document. The default is 0, which means 16,777,216.

Exceptions

MemberOrder

Gets or sets a value that specifies where the fields of a type come among its members.

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlMemberOrder One of the enumeration values that specifies whether the fields of a class come after its properties or before them. The default is XmlMemberOrder.PropertiesFirst.

Exceptions

Remarks

The value matters only for a type with both, and only when XmlSerializerOptions.IncludeFields is true or a field is marked to be included. An explicit order on a member takes precedence.

Namespaces

Gets or sets the namespace declarations that are written on the document element, each as a prefix and the namespace URI it is bound to.

Syntax

Property Value

Type: System.Collections.Generic.IReadOnlyDictionary<string, string>? The declarations, keyed by prefix, in the order they are written, or null for none. An empty prefix is the default namespace. The default is null.

Exceptions

Examples

Remarks

Without this property the serializer declares a namespace where it is first needed and chooses how: as the default namespace of an element, or with a generated prefix such as ns1 for an attribute. A namespace that is declared here is in scope for the whole document, so every element and attribute in it is written with the prefix given here. A declaration is written whether or not anything uses it. When two prefixes are bound to one namespace, the one declared last is used. The declarations are written in the order given, with one exception: the declaration that names the namespace of the document element itself comes first, because the element’s start tag needs it. The declarations are copied when the property is set. Use XmlDocument.DiscoverNamespaces to take them from an existing document, KnownNamespaces for those of a well-known format, or XmlNamespaceDeclarationAttribute to state them on the type. These declarations take precedence over the type’s. An empty prefix declares the default namespace on the document element, so an element with no namespace of its own is in that namespace. When the document element has a namespace of its own that is not this one and has no prefix declared, the two cannot both be written, and serialization throws an InvalidOperationException. The property affects writing only. When the serializer reads, it compares namespace URIs and never prefixes.

NewLine

Gets or sets the line ending that is written.

Syntax

Property Value

Type: string The line ending: "\n" or "\r\n". The default is the value of NewLine.

Exceptions

NumberHandling

Gets or sets a value that specifies whether the named floating-point literals INF, -INF, and NaN are read and written.

Syntax

Property Value

Type: CloudNimble.Text.Xml.Serialization.XmlNumberHandling One of the enumeration values that specifies how named floating-point literals are handled. The default is XmlNumberHandling.AllowNamedFloatingPointLiterals.

Exceptions

OmitXmlDeclaration

Gets or sets a value that indicates whether the XML declaration is omitted from the output.

Syntax

Property Value

Type: bool true if the XML declaration is omitted; otherwise, false. The default is false.

Exceptions

PreferredObjectCreationHandling

Gets or sets the preferred object creation handling for members when deserializing XML.

Syntax

Property Value

Type: CloudNimble.Text.Xml.Serialization.XmlObjectCreationHandling One of the enumeration values that specifies whether a member that already holds a value is given a new one or has the value it holds populated. The default is XmlObjectCreationHandling.Replace.

Exceptions

Remarks

The rules are those of JsonSerializerOptions.PreferredObjectCreationHandling. Under XmlObjectCreationHandling.Replace a member with no setter is not read. Under XmlObjectCreationHandling.Populate the items of a collection and the entries of a dictionary are added to the instance the member holds, and the members of an object are set on it, whether or not the member has a setter. A member that holds null is given a new instance when it has a setter. The option applies only where a member can be populated. An array, an immutable or read-only collection, a polymorphic type, a value with a custom converter, a value type with no setter, and every member of a type that is created through a constructor with parameters are handled as under XmlObjectCreationHandling.Replace. XmlObjectCreationHandlingAttribute sets the handling of one member or one type and takes precedence. XmlObjectCreationHandling.Populate cannot be combined with XmlSerializerOptions.ReferenceHandler: a type with a member to populate throws an InvalidOperationException when it is first used.

PropertyNameCaseInsensitive

Gets or sets a value that indicates whether a property’s name uses a case-insensitive comparison during deserialization.

Syntax

Property Value

Type: bool true if property names are compared case-insensitively; otherwise, false. The default is false.

Exceptions

PropertyNamingPolicy

Gets or sets the policy used to convert a type’s or member’s name to another format, such as camel-casing, when no more specific policy is set.

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlNamingPolicy? A naming policy, or null to leave names unchanged. The default is null.

Exceptions

Remarks

XmlSerializerOptions.ElementNamingPolicy, XmlSerializerOptions.AttributeNamingPolicy, and XmlSerializerOptions.DictionaryKeyPolicy each fall back to this policy when they are null.

ReadCommentHandling

Gets or sets a value that defines how comments are handled during deserialization.

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlCommentHandling One of the enumeration values that indicates whether comments are allowed, disallowed, or skipped. The default is XmlCommentHandling.Skip.

Exceptions

ReferenceHandler

Gets or sets an object that specifies how object references are handled when reading and writing XML.

Syntax

Property Value

Type: CloudNimble.Text.Xml.Serialization.XmlReferenceHandler? The reference handler, or null if object references are not tracked. The default is null.

Exceptions

RespectNullableAnnotations

Gets or sets a value that indicates whether a null is refused for a member or constructor parameter annotated non-nullable.

Syntax

Property Value

Type: bool true if nullability annotations are respected; otherwise, false. The default is false.

Exceptions

Remarks

When this is true, an element marked xsi:nil="true" for a member or constructor parameter that does not accept null throws an XmlException when it is read, and a member annotated as never returning null that holds one throws when it is written. A null that the ignore condition leaves out is not written and is not refused. The rules are those of JsonSerializerOptions.RespectNullableAnnotations. The annotation of the member decides, together with [AllowNull], [DisallowNull], [MaybeNull] and [NotNull]. A member the document leaves out is not checked. The items of a collection, the values of a dictionary, the document root, a member compiled without nullable annotations, and a member whose type is an unconstrained type parameter are not checked either.

RespectRequiredConstructorParameters

Gets or sets a value that indicates whether non-optional constructor parameters must be present in the XML during deserialization.

Syntax

Property Value

Type: bool true if an XmlException is thrown when the XML has no value for a constructor parameter that has no default value; otherwise, false. The default is true.

Exceptions

Strict

Gets a read-only, singleton instance of XmlSerializerOptions that uses the strict configuration.

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlSerializerOptions A read-only instance created with XmlSerializerDefaults.Strict.

TypeInfoResolver

Gets or sets the XmlTypeInfo contract resolver used by this instance.

Syntax

Property Value

Type: CloudNimble.Text.Xml.Serialization.IXmlTypeInfoResolver? The resolver that supplies XmlTypeInfo metadata, or null if none has been set.

Exceptions

Remarks

An instance that has none gets DefaultXmlTypeInfoResolver.Instance when it is first used by an XmlSerializer method that takes options, or by XmlSerializerOptions.MakeReadOnly, if XmlSerializer.IsReflectionEnabledByDefault is true. Those members say that they need reflection, and this property does not, so reading it never brings the reflection resolver into a trimmed program. XmlSerializerOptions.TypeInfoResolverChain is a view of this resolver.

TypeInfoResolverChain

Gets the list of chained XmlTypeInfo contract resolvers used by this instance.

Syntax

Property Value

Type: System.Collections.Generic.IList<CloudNimble.Text.Xml.Serialization.IXmlTypeInfoResolver> The resolvers that make up XmlSerializerOptions.TypeInfoResolver, in the order they are asked.

Remarks

The list is empty until a resolver has been set. Changing the list makes it the XmlSerializerOptions.TypeInfoResolver; setting XmlSerializerOptions.TypeInfoResolver replaces the list’s content.

UnknownTypeHandling

Gets or sets a value that specifies how an element is read into a value declared as Object.

Syntax

Property Value

Type: CloudNimble.Text.Xml.Serialization.XmlUnknownTypeHandling One of the enumeration values that specifies whether the element is read as an XmlElement or as an XmlNode. The default is XmlUnknownTypeHandling.XmlElement.

Exceptions

Remarks

This is the counterpart of JsonSerializerOptions.UnknownTypeHandling. It applies wherever the declared type is Object: a member, an item of a collection, a value of a dictionary, and the document root. An element marked xsi:nil="true" is read as null under both values. Writing is not affected: a value declared as Object is written as the type it has.

UnmappedMemberHandling

Gets or sets a value that specifies how XML elements and attributes that cannot be mapped to a member are handled during deserialization.

Syntax

Property Value

Type: CloudNimble.Text.Xml.Serialization.XmlUnmappedMemberHandling One of the enumeration values that specifies whether an unmapped element or attribute is skipped or rejected. The default is XmlUnmappedMemberHandling.Skip.

Exceptions

UtcOffsetHandling

Gets or sets a value that specifies how a DateTimeOffset whose offset is zero is written.

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlUtcOffsetHandling One of the enumeration values that specifies whether a zero offset is written as +00:00 or as Z. The default is XmlUtcOffsetHandling.WriteOffset.

Exceptions

Remarks

Only writing changes: Z, +00:00 and -00:00 are all read as a zero offset under either value. A DateTime is not affected; its Kind decides what is written.

Web

Gets a read-only, singleton instance of XmlSerializerOptions that uses the web configuration.

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlSerializerOptions A read-only instance created with XmlSerializerDefaults.Web: camel-case names and no XML declaration.

WhitespaceHandling

Gets or sets a value that specifies how white-space-only text between elements is handled during deserialization.

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlWhitespaceHandling One of the enumeration values that specifies how the reader treats white-space-only text between elements. The default is XmlWhitespaceHandling.Insignificant.

Exceptions

WriteIndented

Gets or sets a value that indicates whether XML should use pretty printing. By default, XML is serialized without any extra white space.

Syntax

Property Value

Type: bool true if XML is pretty printed on serialization; otherwise, false. The default is false.

Exceptions

XmlVersion

Gets or sets the XML version of the output, which is written in the XML declaration.

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlVersion One of the enumeration values that specifies the XML version of the output. The default is XmlVersion.Version10.

Exceptions

Methods

Equals Inherited Virtual

Inherited from object

Syntax

Parameters

Returns

Type: bool

Equals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

GetConverter

Returns the converter for the specified type.

Syntax

Parameters

Returns

Type: CloudNimble.Text.Xml.Serialization.XmlConverter The first converter that supports the given type.

Exceptions

Remarks

The first match wins: XmlSerializerOptions.Converters in list order, then XmlConverterAttribute on the type, then the built-in converters.

GetHashCode Inherited Virtual

Inherited from object

Syntax

Returns

Type: int

GetType Inherited

Inherited from object

Syntax

Returns

Type: System.Type

GetTypeInfo

Gets the XmlTypeInfo contract metadata resolved by the current XmlSerializerOptions instance for the specified type, and makes this instance read-only.

Syntax

Parameters

Returns

Type: CloudNimble.Text.Xml.Serialization.XmlTypeInfo The contract metadata resolved for type.

Exceptions

GetTypeInfo

Gets the XmlTypeInfo1` contract metadata resolved by the current XmlSerializerOptions instance for the type specified by a generic type parameter, and makes this instance read-only.

Syntax

Returns

Type: CloudNimble.Text.Xml.Serialization.XmlTypeInfo<T> The contract metadata resolved for T.

Type Parameters

  • T - The type to resolve contract metadata for.

Exceptions

MakeReadOnly

Marks the current instance as read-only to prevent any further user modification.

Syntax

Remarks

Afterwards, every property setter and any change to XmlSerializerOptions.Converters or XmlSerializerOptions.TypeInfoResolverChain throws an InvalidOperationException.

MakeReadOnly

Marks the current instance as read-only to prevent any further user modification, and optionally gives it the reflection-based resolver when it has none.

Syntax

Parameters

Remarks

This is the counterpart of JsonSerializerOptions.MakeReadOnly(bool) in System.Text.Json. The XmlSerializer methods that take options do the same on the first call.

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?

TryGetTypeInfo

Tries to get the XmlTypeInfo contract metadata resolved by the current XmlSerializerOptions instance for the specified type, and makes this instance read-only.

Syntax

Parameters

Returns

Type: bool true if the contract metadata for type was resolved; otherwise, false.

Exceptions

TryGetTypeInfo

Tries to get the XmlTypeInfo1` contract metadata resolved by the current XmlSerializerOptions instance for the type specified by a generic type parameter, and makes this instance read-only.

Syntax

Parameters

Returns

Type: bool true if the contract metadata for T was resolved; otherwise, false.

Type Parameters

  • T - The type to resolve contract metadata for.

Exceptions

  • CloudNimble.Text.Xml.XmlSerializer
  • CloudNimble.Text.Xml.XmlSerializerDefaults
  • CloudNimble.Text.Xml.XmlNamingPolicy
  • CloudNimble.Text.Xml.XmlPropertyMapping
  • CloudNimble.Text.Xml.XmlEnumHandling
  • CloudNimble.Text.Xml.XmlCommentHandling
  • CloudNimble.Text.Xml.XmlWhitespaceHandling
  • CloudNimble.Text.Xml.XmlVersion
  • CloudNimble.Text.Xml.Serialization.XmlIgnoreCondition
  • CloudNimble.Text.Xml.Serialization.XmlUnmappedMemberHandling
  • CloudNimble.Text.Xml.Serialization.XmlNumberHandling
  • CloudNimble.Text.Xml.Serialization.XmlReferenceHandler
  • CloudNimble.Text.Xml.Serialization.XmlConverter
  • CloudNimble.Text.Xml.Serialization.IXmlTypeInfoResolver