YamlUnionTypeStructuralClassifier Class

Classifies YAML payloads into union case types by comparing their YAML shape and, for mappings, their keys.

public sealed class YamlUnionTypeStructuralClassifier : YamlTypeClassifierFactory

Remarks

The default union classification only distinguishes cases that use different YAML shapes, such as a scalar and a sequence. This classifier adds structural classification for cases that serialize as YAML mappings.

To classify a mapping, the classifier starts with every object case as a candidate. For each key at the level of the current mapping, it eliminates candidates that do not declare a matching key. Values and nested content are not examined, and key order does not affect the result. Name matching honors YamlSerializerOptions.PropertyNameCaseInsensitive.

After reading the mapping, candidates missing a required key are eliminated. Missing optional keys have no effect. A key that is not declared 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 several candidates remain. Configurations containing a case that can never be selected uniquely are rejected when the classifier is created.

Inheritance
YamlTypeClassifierFactory YamlUnionTypeStructuralClassifier

Constructors

NameDescription
YamlUnionTypeStructuralClassifier()

YamlUnionTypeStructuralClassifier()

public YamlUnionTypeStructuralClassifier()

No documentation is available.

Methods

NameDescription
CanClassify(YamlTypeClassifierContext)Determines whether this factory can classify the type described by context.
CreateYamlClassifier(YamlTypeClassifierContext, YamlSerializerOptions)Creates the classifier for the type described by context.

CanClassify(YamlTypeClassifierContext)

YamlUnionTypeStructuralClassifier.cs

Determines whether this factory can classify the type described by context.

public override bool CanClassify(YamlTypeClassifierContext context)

Parameters

context YamlTypeClassifierContext
The type being classified.

Returns

bool true when the factory can classify the type; otherwise false.

CreateYamlClassifier(YamlTypeClassifierContext, YamlSerializerOptions)

YamlUnionTypeStructuralClassifier.cs

Creates the classifier for the type described by context.

public override YamlTypeClassifier CreateYamlClassifier(YamlTypeClassifierContext context, YamlSerializerOptions options)

Parameters

context YamlTypeClassifierContext
The type being classified.
options YamlSerializerOptions
The options the classifier is created for.

Returns

YamlTypeClassifier The classifier to select a case with.

Exceptions

ArgumentNullException
context or options is null.
InvalidOperationException
context does not describe a union type.
NotSupportedException
The union declares cases that cannot be told apart.