Table of Contents

BencodeConverter<T> Class

Definition

Namespace
Bodu.Text.Bencode.Serialization
Assembly
Bodu.Text.Bencode.dll
Package
Bodu.Text.Bencode 1.0.0
Source
BencodeConverter{T}.cs

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

public abstract class BencodeConverter<T> : BencodeConverter

Type Parameters

T

The type the converter handles.

Inheritance
BencodeConverter<T>
Inherited Members
Extension Methods

Examples

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

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

Constructors

BencodeConverter()

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

protected BencodeConverter()

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 Utf8BencodeReader, Type, BencodeSerializerOptions)

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

public abstract T Read(ref Utf8BencodeReader reader, Type typeToConvert, BencodeSerializerOptions options)

Parameters

reader Utf8BencodeReader

The reader positioned on the first token of the value.

typeToConvert Type

The requested type.

options BencodeSerializerOptions

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(Utf8BencodeWriter, T, BencodeSerializerOptions)

Writes a value of type T to the writer.

public abstract void Write(Utf8BencodeWriter writer, T value, BencodeSerializerOptions options)

Parameters

writer Utf8BencodeWriter

The destination writer.

value T

The value to write.

options BencodeSerializerOptions

The serializer options in effect.

Applies to

ProductVersions
.NET8, 10