YamlDerivedTypeMappingAttribute Class

Registers a derived type mapping on a source-generated context, enabling cross-project polymorphism.

[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public sealed class YamlDerivedTypeMappingAttribute : YamlAttribute
Inheritance
YamlAttribute YamlDerivedTypeMappingAttribute

Constructors

NameDescription
YamlDerivedTypeMappingAttribute(Type, Type)Initializes a new instance with no discriminator, marking this derived type as the default when no discriminator matches.
YamlDerivedTypeMappingAttribute(Type, Type, int)Initializes a new instance with an integer discriminator.
YamlDerivedTypeMappingAttribute(Type, Type, string)Initializes a new instance with a string discriminator.

YamlDerivedTypeMappingAttribute overloads

YamlDerivedTypeMappingAttribute(Type, Type)

YamlDerivedTypeMappingAttribute.cs

Initializes a new instance with no discriminator, marking this derived type as the default when no discriminator matches.

public YamlDerivedTypeMappingAttribute(Type baseType, Type derivedType)
Parameters
baseType Type
The polymorphic base type.
derivedType Type
The derived CLR type.
Exceptions
ArgumentNullException
baseType or derivedType is null.

YamlDerivedTypeMappingAttribute(Type, Type, int)

YamlDerivedTypeMappingAttribute.cs

Initializes a new instance with an integer discriminator.

public YamlDerivedTypeMappingAttribute(Type baseType, Type derivedType, int discriminator)
Parameters
baseType Type
The polymorphic base type.
derivedType Type
The derived CLR type.
discriminator int
The integer discriminator value.
Exceptions
ArgumentNullException
baseType or derivedType is null.

YamlDerivedTypeMappingAttribute(Type, Type, string)

YamlDerivedTypeMappingAttribute.cs

Initializes a new instance with a string discriminator.

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

Properties

NameDescription
BaseTypeGets the polymorphic base type.
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 polymorphic base type.

public Type BaseType { get; }

Property value

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?