Table of Contents

YamlNumberEnumConverter<TEnum> Class

Definition

Namespace
Bodu.Text.Yaml.Serialization
Assembly
Bodu.Text.Yaml.dll
Package
Bodu.Text.Yaml 1.0.0
Source
NumberEnumConverter{T}.cs

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

public sealed class YamlNumberEnumConverter<TEnum> : YamlConverterFactory where TEnum : struct, Enum

Type Parameters

TEnum

The enumeration type the produced converter handles.

Inheritance
YamlNumberEnumConverter<TEnum>
Inherited Members
Extension Methods

Examples

public sealed class WorkItem
{
    [Converter(typeof(YamlNumberEnumConverter<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. The produced converter writes the numeric value regardless of WriteEnumsAsStrings.

Constructors

YamlNumberEnumConverter()

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

public YamlNumberEnumConverter()

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 the type; otherwise false.

CreateConverter(Type, YamlSerializerOptions)

Creates a converter for the specified type.

public override YamlConverter CreateConverter(Type typeToConvert, YamlSerializerOptions options)

Parameters

typeToConvert Type

The closed type to create a converter for.

options YamlSerializerOptions

The serializer options in effect.

Returns

YamlConverter

A converter that handles typeToConvert.

Applies to

ProductVersions
.NET8, 10