Table of Contents

TomlStringEnumConverter Class

Definition

Namespace
Bodu.Text.Toml.Serialization
Assembly
Bodu.Text.Toml.dll
Package
Bodu.Text.Toml 1.0.0
Source
TomlStringEnumConverter.cs

Produces a converter that serializes any enumeration as a TOML string holding its member name, applying an optional naming policy and honoring StringEnumMemberNameAttribute on individual members.

public sealed class TomlStringEnumConverter : TomlConverterFactory
Inheritance
TomlStringEnumConverter
Inherited Members
Extension Methods

Examples

var options = new TomlSerializerOptions();
options.Converters.Add(new TomlStringEnumConverter(NamingPolicy.SnakeCaseLower, allowIntegerValues: false));

// Status.OnHold now serializes as the TOML string "on_hold".

Remarks

Register the factory on Converters to apply it to every enumeration, or use the generic TomlStringEnumConverter<TEnum> with ConverterAttribute to apply it to a single enumeration. Two constructors are provided: a parameterless form that applies no naming policy and accepts integers on read, and a form that takes an explicit naming policy and integer-handling flag.

Constructors

TomlStringEnumConverter()

Initializes a new instance of the TomlStringEnumConverter class that applies no naming policy and accepts integers on read.

public TomlStringEnumConverter()

TomlStringEnumConverter(NamingPolicy?, bool)

Initializes a new instance of the TomlStringEnumConverter class with the specified naming policy and integer-handling behavior.

public TomlStringEnumConverter(NamingPolicy? namingPolicy, bool allowIntegerValues)

Parameters

namingPolicy NamingPolicy

The naming policy applied to member names, or null to use member names unchanged.

allowIntegerValues bool

Whether a TOML integer is accepted as an enumeration value on read.

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