YamlPolymorphicAttribute Class

Marks a base type as polymorphic for YAML serialization.

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)]
public sealed class YamlPolymorphicAttribute : YamlAttribute
Inheritance
YamlAttribute YamlPolymorphicAttribute

Constructors

NameDescription
YamlPolymorphicAttribute()

YamlPolymorphicAttribute()

YamlPolymorphicAttribute.cs
public YamlPolymorphicAttribute()

No documentation is available.

Properties

NameDescription
DiscriminatorStyleGets or sets the discriminator style.
InferClosedTypePolymorphismGets or sets a value indicating whether derived type registrations are inferred from the compiler-provided metadata of a closed type hierarchy.
TypeDiscriminatorPropertyNameGets or sets the discriminator property name.
UnknownDerivedTypeHandlingGets or sets behavior when an unknown derived type discriminator is encountered.

DiscriminatorStyle

YamlPolymorphicAttribute.cs

Gets or sets the discriminator style.

public YamlTypeDiscriminatorStyle DiscriminatorStyle { get; set; }

InferClosedTypePolymorphism

YamlPolymorphicAttribute.cs

Gets or sets a value indicating whether derived type registrations are inferred from the compiler-provided metadata of a closed type hierarchy.

public bool InferClosedTypePolymorphism { get; set; }

Property value

bool

Remarks

Setting this property overrides YamlPolymorphismOptions.InferClosedTypePolymorphism for the annotated type, so an explicit false suppresses inference even when it is enabled on the serializer options. When the property is left unset the value from the options is used.

Inference is skipped for a type that declares explicit YamlDerivedTypeAttribute registrations. Setting this property to true on a type that is not declared closed throws an InvalidOperationException.

TypeDiscriminatorPropertyName

YamlPolymorphicAttribute.cs

Gets or sets the discriminator property name.

public string? TypeDiscriminatorPropertyName { get; set; }

Property value

string?

UnknownDerivedTypeHandling

YamlPolymorphicAttribute.cs

Gets or sets behavior when an unknown derived type discriminator is encountered.

public YamlUnknownDerivedTypeHandling UnknownDerivedTypeHandling { get; set; }

Property value

YamlUnknownDerivedTypeHandling

Remarks

When set to a value other than YamlUnknownDerivedTypeHandling.Unspecified, this overrides the value from YamlPolymorphismOptions.UnknownDerivedTypeHandling and any value from JsonPolymorphicAttribute.