Skip to main content

Summary

CloudNimble.Text.Xml.Serialization holds the types that shape how XmlSerializer maps .NET objects to XML: the attributes you put on your types, the enumerations that the options use, the base classes for custom converters, and the support types for source generation.

Usage

Import the namespace next to CloudNimble.Text.Xml, then annotate your types:
The code produces the following output:
View the complete sample on GitHub The how-to guides cover each group of attributes: Customize names and shape, Ignore properties, Require properties, Immutable types, and Serialize collections.

Considerations

  • These aren’t the System.Xml.Serialization attributes. Several types here have the same names as attributes in System.Xml.Serialization, such as XmlRootAttribute, XmlElementAttribute, XmlAttributeAttribute, and XmlIgnoreAttribute. The serializer reads only the ones in this namespace. An attribute from System.Xml.Serialization on your type is ignored.
  • Don’t import both namespaces in one file. [XmlElement] would be ambiguous and the file wouldn’t compile. When you move a type over, replace using System.Xml.Serialization; with using CloudNimble.Text.Xml.Serialization;. See Migrate from XmlSerializer.
  • The same names don’t always mean the same defaults. For example, a collection has no wrapper element here unless you add [XmlArray] or set DefaultCollectionMapping to Wrapped. XmlSerializerOptions.Bcl sets the defaults that write what System.Xml.Serialization.XmlSerializer writes.
  • Mapping mistakes are reported on first use. A combination that can’t be mapped, such as [XmlAttribute] on an object member or [XmlText] on a type that also has child elements, throws a NotSupportedException the first time the type is serialized or deserialized.
  • CloudNimble.Text.Xml.XmlSerializer
  • CloudNimble.Text.Xml.XmlSerializerOptions
  • CloudNimble.Text.Xml.XmlNamingPolicy
  • CloudNimble.Text.Xml.XmlPropertyMapping

Types

Classes

Interfaces

Enums