Skip to main content

Definition

Assembly: CloudNimble.XmlEssentials.dll Namespace: CloudNimble.Text.Xml Inheritance: System.Enum

Syntax

Summary

Specifies the predefined sets of options that an XmlSerializerOptions instance can be created with.

Usage

XmlSerializerDefaults names a starting set of option values. Pass a value to the XmlSerializerOptions constructor, then set whatever else you need. It is the counterpart of JsonSerializerDefaults.
When you need a set of defaults exactly as it is, use the ready-made instance instead of creating your own. It is shared and already read-only.

Examples

The following example shows what the strict defaults add to the general ones.

Compare the general and the strict defaults when reading

The strict defaults change reading, apart from refusing to write a null that a nullable annotation forbids. The following example reads a document with a repeated element, one with a comment, and one with an unknown element, first with the general defaults and then with the strict ones.
The code produces the following output:
View the complete sample on GitHub

Considerations

  • Web is smaller than JsonSerializerDefaults.Web. It doesn’t make name matching case-insensitive, and it doesn’t change how numbers are read. Set PropertyNameCaseInsensitive yourself if you need it.
  • With Web, the camelCase policy also applies to the document element, so a type named InvoiceLine is written as <invoiceLine>.
  • Strict changes what is written in one case only: with RespectNullableAnnotations on, a member annotated non-nullable that holds null throws when it is written. It doesn’t set any of the size limits. For XML from an untrusted source, also set MaxDocumentByteCount. See Security.
  • The value is only a starting point. It isn’t stored on the options, so there’s no way to ask an instance which set it was created from.

Values

  • CloudNimble.Text.Xml.XmlSerializerOptions
  • CloudNimble.Text.Xml.XmlSerializer
  • CloudNimble.Text.Xml.XmlNamingPolicy
  • CloudNimble.Text.Xml.XmlCommentHandling
  • CloudNimble.Text.Xml.Serialization.XmlUnmappedMemberHandling