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. On read an integer scalar
outside the range of the underlying type of TEnum throws
YamlSerializationException rather than being narrowed into that type. A value of an
enumeration based on ulong above MaxValue is written as its plain invariant text,
as a ulong member is, and YAML resolves such a plain integer as a string, which the converter reads
back, up to MaxValue, as a ulong member reads it; a quoted or tagged string is
rejected.
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 |