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
TThe 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
typeToConvertTypeThe type to test.
Returns
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
readerUtf8BencodeReaderThe reader positioned on the first token of the value.
typeToConvertTypeThe requested type.
optionsBencodeSerializerOptionsThe 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
writerUtf8BencodeWriterThe destination writer.
valueTThe value to write.
optionsBencodeSerializerOptionsThe serializer options in effect.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |