YamlUnionTypeStructuralClassifier class
Classifies YAML payloads into union case types by comparing their YAML value types and, for YAML objects, their property names.
Namespace: System.Text.Yaml.Serialization · Assembly: Styml.dll
public class YamlUnionTypeStructuralClassifier : YamlTypeClassifierFactory
Inheritance: object → YamlTypeClassifierFactory → YamlUnionTypeStructuralClassifier
Classifies YAML payloads into union case types by comparing their YAML value types and, for YAML objects, their property names.
RemarksLink to this heading
The default union classification distinguishes cases that use different YAML token kinds, such as a string and an array. This classifier adds structural classification for .NET POCOs configured to serialize as YAML objects.
To classify an object, the classifier starts with every POCO case as a candidate. For each property name at the level of the current YAML object, it eliminates candidates that do not define a matching property. Property values and nested content are not examined, and property order does not affect the result. Name matching honors YamlSerializerOptions.PropertyNameCaseInsensitive.
After reading the object, candidates missing a required property are eliminated. Missing optional properties have no effect. A property name that is not defined by any case eliminates only cases configured with YamlUnmappedMemberHandling.Disallow.
The classifier selects the case when exactly one candidate remains. Classification fails when no candidates or multiple candidates remain. Configurations containing a case that can never be selected uniquely are rejected when the classifier is created.
This classifier supports union types only. Nested union cases, polymorphic cases, and reference-preserving deserialization are not supported.
ConstructorsLink to this heading
Initializes a new instance of the YamlUnionTypeStructuralClassifier class.
public YamlUnionTypeStructuralClassifier();
MethodsLink to this heading
CanClassifyLink to this heading
When overridden, indicates whether this factory can produce a classifier for the specified metadata context.
public override bool CanClassify(YamlTypeClassifierContext context);
Parameters
context: The metadata context for the type being configured.
Returns: true if this factory can produce a classifier for context; otherwise false.
CreateYamlClassifierLink to this heading
Creates a delegate that classifies YAML payloads to determine the target type.
public override YamlTypeClassifier CreateYamlClassifier(YamlTypeClassifierContext context, YamlSerializerOptions options);
Parameters
context: An immutable snapshot of metadata including the declaring type, candidate types (with optional discriminator values), and the discriminator property name.options: The serializer options for the current context.
Returns: A YamlTypeClassifier delegate.