YamlDerivedTypeAttribute Class

Registers a derived type for polymorphic YAML serialization.

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true)]
public sealed class YamlDerivedTypeAttribute : YamlAttribute
Inheritance
YamlAttribute YamlDerivedTypeAttribute

Constructors

NameDescription
YamlDerivedTypeAttribute(Type)Initializes a new instance of the YamlDerivedTypeAttribute class with no discriminator. When YamlDerivedTypeAttribute.Tag is also null, this derived type becomes the default when no discriminator or tag matches. When YamlDerivedTypeAttribute.Tag is set, this entry participates only in tag-based dispatch and does not become the default.
YamlDerivedTypeAttribute(Type, int)Initializes a new instance of the YamlDerivedTypeAttribute class with an integer discriminator.
YamlDerivedTypeAttribute(Type, string)Initializes a new instance of the YamlDerivedTypeAttribute class.

YamlDerivedTypeAttribute overloads

YamlDerivedTypeAttribute(Type)

YamlDerivedTypeAttribute.cs

Initializes a new instance of the YamlDerivedTypeAttribute class with no discriminator. When YamlDerivedTypeAttribute.Tag is also null, this derived type becomes the default when no discriminator or tag matches. When YamlDerivedTypeAttribute.Tag is set, this entry participates only in tag-based dispatch and does not become the default.

public YamlDerivedTypeAttribute(Type derivedType)
Parameters
derivedType Type
The derived CLR type.
Exceptions
ArgumentNullException
derivedType is null.

YamlDerivedTypeAttribute(Type, int)

YamlDerivedTypeAttribute.cs

Initializes a new instance of the YamlDerivedTypeAttribute class with an integer discriminator.

public YamlDerivedTypeAttribute(Type derivedType, int discriminator)
Parameters
derivedType Type
The derived CLR type.
discriminator int
The integer discriminator value.
Exceptions
ArgumentNullException
derivedType is null.

YamlDerivedTypeAttribute(Type, string)

YamlDerivedTypeAttribute.cs

Initializes a new instance of the YamlDerivedTypeAttribute class.

public YamlDerivedTypeAttribute(Type derivedType, string discriminator)
Parameters
derivedType Type
The derived CLR type.
discriminator string
The discriminator value.
Exceptions
ArgumentNullException
derivedType or discriminator is null.

Properties

NameDescription
DerivedTypeGets the derived CLR type.
DiscriminatorGets the discriminator value, or null if this is the default derived type.
TagGets or sets an optional explicit YAML tag for the derived type.

Gets the derived CLR type.

public Type DerivedType { get; }

Property value

Type

Gets the discriminator value, or null if this is the default derived type.

public string? Discriminator { get; }

Property value

string?

Gets or sets an optional explicit YAML tag for the derived type.

public string? Tag { get; set; }

Property value

string?