TomlStringEnumConverter<TEnum> Class
Definition
Produces a converter that serializes the enumeration TEnum as a TOML string holding its
member name, applying an optional naming policy and honoring StringEnumMemberNameAttribute on
individual members.
public sealed class TomlStringEnumConverter<TEnum> : TomlConverterFactory where TEnum : struct, Enum
Type Parameters
TEnumThe enumeration type the produced converter handles.
- Inheritance
-
TomlStringEnumConverter<TEnum>
- Inherited Members
- Extension Methods
Examples
[Converter(typeof(TomlStringEnumConverter<Status>))]
public enum Status
{
Active,
OnHold,
}
// Status.OnHold serializes as the TOML string "OnHold".
Remarks
Unlike the non-generic TomlStringEnumConverter, this strongly typed factory can be referenced from a ConverterAttribute on a member, property, or the enumeration itself, because it exposes a public parameterless constructor and applies to a single enumeration type.
Constructors
TomlStringEnumConverter()
Initializes a new instance of the TomlStringEnumConverter<TEnum> class that applies no naming policy and accepts integers on read.
public TomlStringEnumConverter()
TomlStringEnumConverter(NamingPolicy?, bool)
Initializes a new instance of the TomlStringEnumConverter<TEnum> class with the specified naming policy and integer-handling behavior.
public TomlStringEnumConverter(NamingPolicy? namingPolicy, bool allowIntegerValues)
Parameters
namingPolicyNamingPolicyThe naming policy applied to member names, or null to use member names unchanged.
allowIntegerValuesboolWhether 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
typeToConvertTypeThe type to test.
Returns
CreateConverter(Type, TomlSerializerOptions)
Creates a converter for the specified type.
public override TomlConverter CreateConverter(Type typeToConvert, TomlSerializerOptions options)
Parameters
typeToConvertTypeThe closed type to create a converter for.
optionsTomlSerializerOptionsThe serializer options in effect.
Returns
- TomlConverter
A converter that handles
typeToConvert.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |