Definition
Assembly: CloudNimble.XmlEssentials.dll Namespace: CloudNimble.Text.Xml.Serialization Inheritance: CloudNimble.Text.Xml.Serialization.XmlDerivedTypeAttributeSyntax
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 toDisc.
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>:
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
Tderives from the type the attribute is on, so keep the two in the same hierarchy. - The discriminator is always a string.
TypeDiscriminatoris typed asobjectto match the shape ofJsonDerivedTypeAttribute, 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.
Namespaceis the namespace of the element that is named for the derived type. Leftnull, 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.
Namespaceapplies when the discriminator is the element name. WithXmlDiscriminatorPlacement.AttributeorXsiTypethere is no such element, and aNamespacethat isn’tnullthrows aNotSupportedExceptionthe 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 theXmlDerivedTypeAttribute1` class that uses the name of T as the type discriminator.
Syntax
.ctor
Initializes a new instance of theXmlDerivedTypeAttribute1` class with the specified type discriminator.
Syntax
Parameters
Exceptions
.ctor Inherited
Inherited from
CloudNimble.Text.Xml.Serialization.XmlDerivedTypeAttributeSyntax
.ctor Inherited
Inherited from
System.AttributeSyntax
.ctor Inherited
Inherited from
objectSyntax
Properties
DerivedType Override
Syntax
Property Value
Type:System.Type
DerivedType Inherited Abstract
Inherited from
CloudNimble.Text.Xml.Serialization.XmlDerivedTypeAttributeSyntax
Property Value
Type:System.Type
The derived type.
Namespace Inherited
Inherited from
CloudNimble.Text.Xml.Serialization.XmlDerivedTypeAttributeSyntax
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 notnull 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.XmlDerivedTypeAttributeSyntax
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.AttributeSyntax
Property Value
Type:object
Methods
Equals Override
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
Equals Inherited Virtual
Inherited from
objectSyntax
Parameters
Returns
Type:bool
Equals Inherited
Inherited from
objectSyntax
Parameters
Returns
Type:bool
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetHashCode Override
Inherited from
System.AttributeSyntax
Returns
Type:int
GetHashCode Inherited Virtual
Inherited from
objectSyntax
Returns
Type:int
GetType Inherited
Inherited from
objectSyntax
Returns
Type:System.Type
IsDefaultAttribute Inherited Virtual
Inherited from
System.AttributeSyntax
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
Match Inherited Virtual
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
MemberwiseClone Inherited
Inherited from
objectSyntax
Returns
Type:object
ReferenceEquals Inherited
Inherited from
objectSyntax
Parameters
Returns
Type:bool
ToString Inherited Virtual
Inherited from
objectSyntax
Returns
Type:string?
Related APIs
- CloudNimble.Text.Xml.Serialization.XmlPolymorphicAttribute
- CloudNimble.Text.Xml.Serialization.XmlUnknownDerivedTypeHandling
- CloudNimble.Text.Xml.Serialization.XmlIncludeAttribute
- CloudNimble.Text.Xml.XmlDiscriminatorPlacement