Table of Contents

BencodeStringEnumConverter<TEnum> Class

Definition

Namespace
Bodu.Text.Bencode.Serialization
Assembly
Bodu.Text.Bencode.dll
Package
Bodu.Text.Bencode 1.0.0
Source
BencodeStringEnumConverter{T}.cs

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

public sealed class BencodeStringEnumConverter<TEnum> : BencodeConverterFactory where TEnum : struct, Enum

Type Parameters

TEnum

The enumeration type the produced converter handles.

Inheritance
BencodeStringEnumConverter<TEnum>
Inherited Members
Extension Methods

Examples

[Converter(typeof(BencodeStringEnumConverter<Status>))]
public enum Status
{
    Active,
    OnHold,
}

// Status.OnHold serializes as the byte string 6:OnHold.

Remarks

Unlike the non-generic BencodeStringEnumConverter, 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

BencodeStringEnumConverter()

Initializes a new instance of the BencodeStringEnumConverter<TEnum> class that applies no naming policy and accepts integers on read.

public BencodeStringEnumConverter()

BencodeStringEnumConverter(NamingPolicy?, bool)

Initializes a new instance of the BencodeStringEnumConverter<TEnum> class with the specified naming policy and integer-handling behavior.

public BencodeStringEnumConverter(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 Bencode 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, BencodeSerializerOptions)

Creates a converter for the specified type.

public override BencodeConverter CreateConverter(Type typeToConvert, BencodeSerializerOptions options)

Parameters

typeToConvert Type

The closed type to create a converter for.

options BencodeSerializerOptions

The serializer options in effect.

Returns

BencodeConverter

A converter that handles typeToConvert.

Applies to

ProductVersions
.NET8, 10