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