YamlUnionTypeStructuralClassifier Class
Classifies YAML payloads into union case types by comparing their YAML shape and, for mappings, their keys.
public sealed class YamlUnionTypeStructuralClassifier : YamlTypeClassifierFactoryRemarks
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
YamlTypeClassifierFactoryYamlUnionTypeStructuralClassifier
Constructors
| Name | Description |
|---|---|
| YamlUnionTypeStructuralClassifier() |
YamlUnionTypeStructuralClassifier()
public YamlUnionTypeStructuralClassifier()No documentation is available.
Methods
| Name | Description |
|---|---|
| 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.csDetermines whether this factory can classify the type described by context.
public override bool CanClassify(YamlTypeClassifierContext context)Parameters
contextYamlTypeClassifierContext- The type being classified.
Returns
bool true when the factory can classify the type; otherwise false.
CreateYamlClassifier(YamlTypeClassifierContext, YamlSerializerOptions)
YamlUnionTypeStructuralClassifier.csCreates the classifier for the type described by context.
public override YamlTypeClassifier CreateYamlClassifier(YamlTypeClassifierContext context, YamlSerializerOptions options)Parameters
contextYamlTypeClassifierContext- The type being classified.
optionsYamlSerializerOptions- The options the classifier is created for.
Returns
YamlTypeClassifier The classifier to select a case with.
Exceptions
ArgumentNullExceptioncontextoroptionsisnull.InvalidOperationExceptioncontextdoes not describe a union type.NotSupportedException- The union declares cases that cannot be told apart.