Table of Contents

TomlConverter<T> Class

Definition

Namespace
Bodu.Text.Toml.Serialization
Assembly
Bodu.Text.Toml.dll
Package
Bodu.Text.Toml 1.0.0
Source
TomlConverter{T}.cs

Converts a value of type T to and from the TOML reader and writer. This is the base authors derive to customize how a specific type is serialized.

public abstract class TomlConverter<T> : TomlConverter

Type Parameters

T

The type the converter handles.

Inheritance
TomlConverter<T>
Inherited Members
Extension Methods

Examples

public sealed class VersionConverter : TomlConverter<Version>
{
    public override Version Read(ref TomlDocumentReader reader, Type typeToConvert, TomlSerializerOptions options) =>
        Version.Parse(reader.GetString());

    public override void Write(Utf8TomlWriter writer, Version value, TomlSerializerOptions options) =>
        writer.WriteString(value.ToString());
}

Constructors

TomlConverter()

Initializes a new instance of the TomlConverter<T> class.

protected TomlConverter()

Methods

CanConvert(Type)

Determines whether the converter can convert the specified type.

public override bool CanConvert(Type typeToConvert)

Parameters

typeToConvert Type

The type to test.

Returns

bool

true when the converter handles typeToConvert; otherwise false.

Read(ref TomlDocumentReader, Type, TomlSerializerOptions)

Reads and converts a value of type T from the reader.

public abstract T Read(ref TomlDocumentReader reader, Type typeToConvert, TomlSerializerOptions options)

Parameters

reader TomlDocumentReader

The reader positioned on the first token of the value.

typeToConvert Type

The requested type.

options TomlSerializerOptions

The serializer options in effect.

Returns

T

The deserialized 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(Utf8TomlWriter, T, TomlSerializerOptions)

Writes a value of type T to the writer.

public abstract void Write(Utf8TomlWriter writer, T value, TomlSerializerOptions options)

Parameters

writer Utf8TomlWriter

The destination writer.

value T

The value to write.

options TomlSerializerOptions

The serializer options in effect.

Applies to

ProductVersions
.NET8, 10