YamlConverter<T> Class
Definition
- Namespace
- Bodu.Text.Yaml.Serialization
- Assembly
- Bodu.Text.Yaml.dll
- Package
- Bodu.Text.Yaml 1.0.0
- Source
- YamlConverter{T}.cs
Serves as the strongly-typed base for custom YAML converters that read and write values of type
T. This is the base authors derive to customize how a specific type is serialized.
public abstract class YamlConverter<T> : YamlConverter
Type Parameters
TThe type handled by the converter.
- Inheritance
-
YamlConverter<T>
- Inherited Members
- Extension Methods
Examples
public sealed class VersionConverter : YamlConverter<Version>
{
public override Version Read(ref Utf8YamlReader reader, Type typeToConvert, YamlSerializerOptions options) =>
Version.Parse(reader.GetString());
public override void Write(Utf8YamlWriter writer, Version value, YamlSerializerOptions options) =>
writer.WriteString(value.ToString());
}
Constructors
YamlConverter()
protected YamlConverter()
Methods
CanConvert(Type)
Determines whether the converter can convert the specified type.
public override bool CanConvert(Type typeToConvert)
Parameters
typeToConvertTypeThe type to test.
Returns
Read(ref Utf8YamlReader, Type, YamlSerializerOptions)
Reads and converts a value of type T from the reader.
public abstract T Read(ref Utf8YamlReader reader, Type typeToConvert, YamlSerializerOptions options)
Parameters
readerUtf8YamlReaderThe reader positioned on the first token of the value.
typeToConvertTypeThe requested type.
optionsYamlSerializerOptionsThe serializer options in effect.
Returns
- T
The converted value.
Remarks
On entry the reader is positioned on the value's first token. On return it must be positioned on the value's last token, so the caller can advance past the value with a single Read().
Write(Utf8YamlWriter, T, YamlSerializerOptions)
Writes a value of type T as YAML.
public abstract void Write(Utf8YamlWriter writer, T value, YamlSerializerOptions options)
Parameters
writerUtf8YamlWriterThe writer to emit into.
valueTThe value to write.
optionsYamlSerializerOptionsThe serializer options in effect.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |