Skip to main content

Definition

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

Syntax

Summary

Specifies how enumeration values are written.

Usage

XmlEnumHandling is the type of XmlSerializerOptions.EnumHandling. It decides whether an enumeration value is written as the name of its member or as its number. The default is Name.
The code produces the following output:
The last call reads the numeric document with the default options, which shows that a number is accepted when reading even though EnumHandling is Name. View the complete sample on GitHub

Considerations

  • The setting affects writing. It applies to enumeration members written as elements and as attributes.
  • With Name, a [Flags] value is written as the names of its flags separated by spaces, for example Class Struct. A value that has no name is written as its number.
  • A name that isn’t a member of the enumeration is an XmlException when read, with the message The value is not a valid enum member.
  • Names are more readable and survive a renumbering of the enumeration. Numbers survive a rename. Choose the form that matches how the type is expected to change.
  • System.Text.Json writes enumerations as numbers by default and needs JsonStringEnumConverter for names. XmlEssentials writes names by default, as System.Xml.Serialization does.

Values

  • CloudNimble.Text.Xml.XmlSerializerOptions
  • CloudNimble.Text.Xml.XmlSerializer
  • CloudNimble.Text.Xml.Serialization.XmlSourceGenerationOptionsAttribute