YamlPolymorphicAttribute class
When placed on a type, indicates that the type should be serialized polymorphically.
Namespace: System.Text.Yaml.Serialization ยท Assembly: Styml.dll
public sealed class YamlPolymorphicAttribute : YamlAttribute
Inheritance: object โ Attribute โ YamlAttribute โ YamlPolymorphicAttribute
When placed on a type, indicates that the type should be serialized polymorphically.
ConstructorsLink to this heading
public YamlPolymorphicAttribute();
PropertiesLink to this heading
DiscriminatorStyleLink to this heading
Gets or sets how a value says which derived type it is: the $type property (the default), a YAML tag, or both. Reading accepts the property under every style.
public YamlTypeDiscriminatorStyle DiscriminatorStyle { get; set; }
IgnoreUnrecognizedTypeDiscriminatorsLink to this heading
When set to true, instructs the deserializer to ignore any unrecognized type discriminator id's and reverts to the contract of the base type. Otherwise, it will fail the deserialization.
public bool IgnoreUnrecognizedTypeDiscriminators { get; set; }
InferClosedTypePolymorphismLink to this heading
Gets or sets a value that indicates whether derived type registrations should be inferred from compiler-provided metadata for a closed type hierarchy.
public bool InferClosedTypePolymorphism { get; set; }
Value: true to infer derived type registrations; otherwise, false. The default is false.
Setting this property overrides YamlSerializerOptions.InferClosedTypePolymorphism for the annotated type, so an explicit false suppresses inference even when it is enabled globally. When the property is left unset the globally configured value is used. If the annotated type declares one or more YamlDerivedTypeAttribute registrations, inference is skipped for that type and only the explicitly registered derived types are used. Closed derived types are expanded recursively and only terminal derived types are registered. Polymorphism configuration declared on derived types applies to their respective contracts and does not affect inference for the annotated type.
TypeClassifierLink to this heading
Gets or sets the type of a YamlTypeClassifierFactory implementation used to classify YAML payloads during deserialization instead of relying on the standard type discriminator property.
public Type? TypeClassifier { get; set; }
When set, the classifier is invoked before any discriminator-based resolution. The classifier receives a Utf8YamlReader positioned at the start of the YAML object and returns the resolved Type. Returning null fails deserialization.
The specified type must derive from YamlTypeClassifierFactory and have a public parameterless constructor.
TypeDiscriminatorPropertyNameLink to this heading
Gets or sets a custom type discriminator property name for the polymorphic type. Uses the default '$type' property name if left unset.
public string? TypeDiscriminatorPropertyName { get; set; }
UnknownDerivedTypeHandlingLink to this heading
Gets or sets the behavior when serializing an undeclared derived runtime type.
public YamlUnknownDerivedTypeHandling UnknownDerivedTypeHandling { get; set; }