Table of Contents

Class EnumNameJson<TEnum>

Namespace
PolyMod.Json
Assembly
PolyMod.dll

The JSON converter that reads and writes an enum value as its C# member name. The JSON form is a string, for example "Linear".

public class EnumNameJson<TEnum> : JsonConverter<TEnum> where TEnum : struct, Enum

Type Parameters

TEnum

The enum type to convert.

Inheritance
EnumNameJson<TEnum>
Inherited Members

Remarks

Use this converter for enums that mods cannot extend and that EnumCache does not have.

Methods

Read(ref Utf8JsonReader, Type, JsonSerializerOptions)

Reads a JSON string and gets the enum value with that member name. The name is not case-sensitive. The method uses Enum.TryParse, so it also accepts numeric strings.

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

Parameters

reader Utf8JsonReader

The JSON reader, at a string token.

typeToConvert Type

The type to read. The method does not use it.

options JsonSerializerOptions

The serializer options. The method does not use them.

Returns

TEnum

The enum value that has the name in the JSON string.

Exceptions

JsonException

The JSON value is null or is not a member name of TEnum. The message shows the valid names.

Write(Utf8JsonWriter, TEnum, JsonSerializerOptions)

Writes the enum value as a JSON string with its C# member name.

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

Parameters

writer Utf8JsonWriter

The JSON writer.

value TEnum

The enum value to write.

options JsonSerializerOptions

The serializer options. The method does not use them.