Table of Contents

Class ExtensibleEnumConverter<T>

Namespace
Cloudflare.NET.Core.Json
Assembly
Cloudflare.NET.dll

A JSON converter for extensible enum types that implement IExtensibleEnum<TSelf>.

This converter serializes extensible enums as their underlying string value and deserializes JSON strings back into the appropriate extensible enum type.

public class ExtensibleEnumConverter<T> : JsonConverter<T> where T : struct, IExtensibleEnum<T>

Type Parameters

T

The extensible enum type to convert.

Inheritance
ExtensibleEnumConverter<T>
Inherited Members

Examples

// Direct attribute application
[JsonConverter(typeof(ExtensibleEnumConverter<R2LocationHint>))]
public R2LocationHint Location { get; set; }

Remarks

When deserializing, null JSON values result in default(T). For nullable properties, consider using Nullable<T> with this converter.

This converter supports both direct application via JsonConverterAttribute and registration through Converters.

Methods

Read(ref Utf8JsonReader, Type, JsonSerializerOptions)

Reads and converts the JSON to type T.

public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)

Parameters

reader Utf8JsonReader

The reader.

typeToConvert Type

The type to convert.

options JsonSerializerOptions

An object that specifies serialization options to use.

Returns

T

The converted value.

Write(Utf8JsonWriter, T, JsonSerializerOptions)

Writes a specified value as JSON.

public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)

Parameters

writer Utf8JsonWriter

The writer to write to.

value T

The value to convert to JSON.

options JsonSerializerOptions

An object that specifies serialization options to use.