Table of Contents

TomlNumberEnumConverter<TEnum> Class

Definition

Namespace
Bodu.Text.Toml.Serialization
Assembly
Bodu.Text.Toml.dll
Package
Bodu.Text.Toml 1.3.0
Source
NumberEnumConverter{T}.cs

Produces a converter that serializes the enumeration TEnum as a TOML integer carrying its underlying numeric value.

public sealed class TomlNumberEnumConverter<TEnum> : TomlConverterFactory where TEnum : struct, Enum

Type Parameters

TEnum

The enumeration type the produced converter handles.

Inheritance
TomlNumberEnumConverter<TEnum>
Inherited Members
Extension Methods

Examples

public sealed class WorkItem
{
    [Converter(typeof(TomlNumberEnumConverter<Priority>))]
    public Priority Priority { get; set; }
}

// Priority.High (underlying value 2) serializes as: Priority = 2

Remarks

Reference the factory from a ConverterAttribute on a member, property, or the enumeration itself, or register it on Converters. It exposes a public parameterless constructor so it can be used through the converter attribute. On read an integer outside the range of the underlying type of TEnum throws TomlSerializationException rather than being narrowed into that type. A TOML integer is a signed 64-bit value, so an enumeration based on ulong reads integers up to MaxValue, and writing a larger value throws TomlSerializationException, as writing such a ulong member does.

Constructors

TomlNumberEnumConverter()

Initializes a new instance of the TomlNumberEnumConverter<TEnum> class.

public TomlNumberEnumConverter()

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.

CreateConverter(Type, TomlSerializerOptions)

Creates a converter for the specified type.

public override TomlConverter CreateConverter(Type typeToConvert, TomlSerializerOptions options)

Parameters

typeToConvert Type

The closed type to create a converter for.

options TomlSerializerOptions

The serializer options in effect.

Returns

TomlConverter

A converter that handles typeToConvert.

Applies to

ProductVersions
.NET8, 10