YamlNumberEnumConverter<TEnum> Class
Definition
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
TEnumThe 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
typeToConvertTypeThe type to test.
Returns
CreateConverter(Type, YamlSerializerOptions)
Creates a converter for the specified type.
public override YamlConverter CreateConverter(Type typeToConvert, YamlSerializerOptions options)
Parameters
typeToConvertTypeThe closed type to create a converter for.
optionsYamlSerializerOptionsThe serializer options in effect.
Returns
- YamlConverter
A converter that handles
typeToConvert.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |