Skip to main content

Definition

Assembly: CloudNimble.XmlEssentials.dll Namespace: CloudNimble.Text.Xml.Serialization Inheritance: CloudNimble.Text.Xml.Serialization.XmlDerivedTypeAttribute

Syntax

Summary

Indicates, when placed on a type declaration, that T is opted into polymorphic serialization and can appear where the annotated type is expected. This class cannot be inherited.

Usage

XmlDerivedTypeAttribute is the abstract base of XmlDerivedTypeAttribute<T>, which is the attribute you apply. Put one [XmlDerivedType<T>] on a base class for each derived type that can appear where the base type is declared.
  • [XmlDerivedType<Book>] uses the type’s name, Book, as the discriminator.
  • [XmlDerivedType<Dvd>("Disc")] sets the discriminator to Disc.
What the discriminator is depends on XmlPolymorphicAttribute.DiscriminatorPlacement: the name of the element, the value of a named attribute, or the value of xsi:type. With the default placement, a Dvd in a list of products is written as <Disc>:
See Serialize derived classes and the polymorphism sample.

Type Parameters

  • T - The derived type that is supported in polymorphic serialization of the annotated type.

Considerations

  • The type argument is checked by the compiler, which is why the attribute is generic. The serializer doesn’t verify that T derives from the type the attribute is on, so keep the two in the same hierarchy.
  • The discriminator is always a string. TypeDiscriminator is typed as object to match the shape of JsonDerivedTypeAttribute, but there is no integer form.
  • When the discriminator is an element name, the element naming policy of the options is applied to it. When it is an attribute value, it is written as declared.
  • Namespace is the namespace of the element that is named for the derived type. Left null, the element is written under its name alone, in the default namespace that is in scope. An empty string puts it in no namespace.
  • A derived type that has a namespace is matched by its local name and its namespace when a document is read, so two derived types can have one local name in two namespaces. A derived type with no namespace is matched by its local name alone.
  • Namespace applies when the discriminator is the element name. With XmlDiscriminatorPlacement.Attribute or XsiType there is no such element, and a Namespace that isn’t null throws a NotSupportedException the first time the type is used.
  • In System.Xml.Serialization, the same job is done by [XmlInclude(typeof(T))]. In this library [XmlInclude] means something else: it opts a non-public member in to serialization.

Constructors

.ctor

Initializes a new instance of the XmlDerivedTypeAttribute1` class that uses the name of T as the type discriminator.

Syntax

.ctor

Initializes a new instance of the XmlDerivedTypeAttribute1` class with the specified type discriminator.

Syntax

Parameters

Exceptions

.ctor Inherited

Inherited from CloudNimble.Text.Xml.Serialization.XmlDerivedTypeAttribute
Called from constructors in derived classes to initialize the XmlDerivedTypeAttribute class.

Syntax

.ctor Inherited

Inherited from System.Attribute

Syntax

.ctor Inherited

Inherited from object

Syntax

Properties

DerivedType Override

Syntax

Property Value

Type: System.Type

DerivedType Inherited Abstract

Inherited from CloudNimble.Text.Xml.Serialization.XmlDerivedTypeAttribute
When overridden in a derived class, gets the derived type that is supported in polymorphic serialization of the declared base type.

Syntax

Property Value

Type: System.Type The derived type.

Namespace Inherited

Inherited from CloudNimble.Text.Xml.Serialization.XmlDerivedTypeAttribute
Gets or sets the namespace URI of the element that identifies the derived type.

Syntax

Property Value

Type: string? The namespace URI. The default is null, which writes the element under its name alone, so it is in the default namespace that is in scope. An empty string puts the element in no namespace.

Remarks

The value applies when the derived type is identified by the name of its element, which is XmlDiscriminatorPlacement.ElementName. With another placement there is no such element, and a value that is not null is refused with a NotSupportedException the first time the type is used. When a document is read, a derived type that has a namespace is matched by its local name and its namespace, so two derived types can have one local name in two namespaces. A derived type with no namespace is matched by its local name alone.

TypeDiscriminator Inherited

Inherited from CloudNimble.Text.Xml.Serialization.XmlDerivedTypeAttribute
Gets or sets the type discriminator identifier that is used for the serialization of the derived type.

Syntax

Property Value

Type: object? The type discriminator. Depending on XmlPolymorphicAttribute.DiscriminatorPlacement, it is the local name of the element or the value of the discriminator attribute. If the value is not a string, the name of XmlDerivedTypeAttribute.DerivedType is used.

Remarks

When the discriminator is an element name, the element naming policy is applied to it.

TypeId Inherited Virtual

Inherited from System.Attribute

Syntax

Property Value

Type: object

Methods

Equals Override

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

Equals Inherited Virtual

Inherited from object

Syntax

Parameters

Returns

Type: bool

Equals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetHashCode Override

Inherited from System.Attribute

Syntax

Returns

Type: int

GetHashCode Inherited Virtual

Inherited from object

Syntax

Returns

Type: int

GetType Inherited

Inherited from object

Syntax

Returns

Type: System.Type

IsDefaultAttribute Inherited Virtual

Inherited from System.Attribute

Syntax

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

Match Inherited Virtual

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

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?
  • CloudNimble.Text.Xml.Serialization.XmlPolymorphicAttribute
  • CloudNimble.Text.Xml.Serialization.XmlUnknownDerivedTypeHandling
  • CloudNimble.Text.Xml.Serialization.XmlIncludeAttribute
  • CloudNimble.Text.Xml.XmlDiscriminatorPlacement