YamlTypeClassifierFactory class
When implemented in a derived class, creates a YamlTypeClassifier delegate that classifies YAML payloads to determine the target type.
Namespace: System.Text.Yaml.Serialization · Assembly: Styml.dll
public abstract class YamlTypeClassifierFactory
Derived: YamlTypeClassifierFactory<T>, YamlUnionTypeStructuralClassifier
When implemented in a derived class, creates a YamlTypeClassifier delegate that classifies YAML payloads to determine the target type.
RemarksLink to this heading
This factory is the extension point for users who want to customize how YAML payloads are matched to union case types or polymorphic derived types during deserialization. It is referenced by the YamlUnionAttribute.TypeClassifier and YamlPolymorphicAttribute.TypeClassifier properties.
The factory's YamlTypeClassifierFactory.CreateYamlClassifier method is called once during YamlTypeInfo configuration, and the returned delegate is invoked on every deserialization call.
A single factory may produce type classifiers for multiple declaring types — analogous to YamlConverterFactory. Implementations report supported metadata shapes via YamlTypeClassifierFactory.CanClassify. For the common case of a factory pinned to a single declaring type, derive from YamlTypeClassifierFactory<T> instead.
Factories may be registered globally on YamlSerializerOptions.TypeClassifiers or per-type via YamlUnionAttribute.TypeClassifier / YamlPolymorphicAttribute.TypeClassifier. When both are present the attribute wins.
For union types, the produced classifier delegate is not invoked when the payload is a YAML YamlTokenType.Null token. The converter handles null payloads directly: it produces the canonical null union value when at least one case is nullable, and otherwise throws a YamlException. See YamlTypeClassifier for details.
ConstructorsLink to this heading
protected YamlTypeClassifierFactory();
MethodsLink to this heading
CanClassifyLink to this heading
When overridden, indicates whether this factory can produce a classifier for the specified metadata context.
public abstract 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 abstract 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.