YamlConverter<T> class

Converts an object or value to or from YAML.

Namespace: System.Text.Yaml.Serialization · Assembly: Styml.dll

public abstract class YamlConverter<T> : YamlConverter

Inheritance: object → YamlConverter → YamlConverter

Converts an object or value to or from YAML.

Type parameters

  • T: The Type to convert.

ConstructorsLink to this heading

When overridden, constructs a new YamlConverter<T> instance.

protected internal YamlConverter();

PropertiesLink to this heading

HandleNullLink to this heading

Indicates whether null should be passed to the converter on serialization, and whether YamlTokenType.Null should be passed on deserialization.

public virtual bool HandleNull { get; }

The default value is true for converters based on value types, and false for converters based on reference types.

TypeLink to this heading

Gets the type being converted by the current converter instance.

public sealed override Type Type { get; }

For instances of type YamlConverter<T> returns typeof(T), and for instances of type YamlConverterFactory returns null.

MethodsLink to this heading

CanConvertLink to this heading

Determines whether the type can be converted.

public override bool CanConvert(Type typeToConvert);

Parameters

  • typeToConvert:

Returns: True if the type can be converted, False otherwise.

The default implementation is to return True when typeToConvert equals typeof(T).

ReadLink to this heading

Read and convert the YAML to T.

public abstract T? Read(ref Utf8YamlReader reader, Type typeToConvert, YamlSerializerOptions options);

Parameters

Returns: The value that was converted.

A converter may throw any Exception, but should throw YamlException when the YAML is invalid.

ReadAsPropertyNameLink to this heading

Reads a dictionary key from a YAML property name.

public virtual T? ReadAsPropertyName(ref Utf8YamlReader reader, Type typeToConvert, YamlSerializerOptions options);

Parameters

Returns: The value that was converted.

Method should be overridden in custom converters of types used in deserialized dictionary keys.

WriteLink to this heading

Write the value as YAML.

public abstract void Write(Utf8YamlWriter writer, T value, YamlSerializerOptions options);

Parameters

A converter may throw any Exception, but should throw YamlException when the YAML cannot be created.

WriteAsPropertyNameLink to this heading

Writes a dictionary key as a YAML property name.

public virtual void WriteAsPropertyName(Utf8YamlWriter writer, T? value, YamlSerializerOptions options);

Parameters

Method should be overridden in custom converters of types used in serialized dictionary keys.

Generated from the XML documentation of the libraryBuilt with Douze

Esc to close