Skip to main content

Definition

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

Syntax

Summary

Specifies where a polymorphic type discriminator is written.

Usage

XmlDiscriminatorPlacement is the type of XmlPolymorphicAttribute.DiscriminatorPlacement. It decides how a document says which derived type an element holds. The following base type identifies its derived types with a kind attribute:
A Checkout object whose Payment member holds a CardPayment is written as follows:
For complete examples of each placement, see Serialize derived classes and the polymorphism sample.

Considerations

  • ElementName changes the name of the element, so it suits a list or a member whose element name isn’t fixed by a schema. An object of the base type itself keeps the member’s own element name.
  • Under every placement, a value whose type is the declared type of the member, the item or the document element is written with no discriminator, even when that declared type is itself one of the derived types. Only a type below the declared type is identified. With Attribute or XsiType, and for the items of a wrapped collection, a discriminator that names a type that isn’t the declared type or below it throws an XmlException: The element identifies the type '...', which is not a '...'. With ElementName, an element named for such a type isn’t an element of the member at all: it is content that no member maps, skipped by default and an error under XmlUnmappedMemberHandling.Disallow.
  • Attribute requires XmlPolymorphicAttribute.TypeDiscriminatorPropertyName. Without it, the serializer throws NotSupportedException when it builds the type’s metadata. The attribute is in no namespace.
  • XsiType writes the discriminator string as the value of xsi:type, with no namespace prefix inside the value. It matches the attribute that System.Xml.Serialization writes, but the serializer doesn’t resolve the value as a schema type name.
  • With Attribute and XsiType, the discriminator can be anywhere in the start tag. With ElementName, an element whose name isn’t declared is treated as content that no member maps.
  • The placement is set for each base type, on its [XmlPolymorphic] attribute. XmlSerializerOptions has no property for it.

Values

  • CloudNimble.Text.Xml.Serialization.XmlPolymorphicAttribute
  • CloudNimble.Text.Xml.Serialization.XmlDerivedTypeAttribute
  • CloudNimble.Text.Xml.Serialization.XmlUnknownDerivedTypeHandling
  • CloudNimble.Text.Xml.XmlNamespaces
  • CloudNimble.Text.Xml.XmlAttributes