namespace Uwaa.Pleroma; /// /// Converts to and from enum values in lowercase. /// class EnumLowerCaseConverter : JsonConverter where T : struct { public override bool CanConvert(Type typeToConvert) => typeToConvert.IsEnum; public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { return Enum.Parse(reader.GetString() ?? throw new NullReferenceException("Expected a string, got null"), true); } public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) { writer.WriteStringValue(value.ToString()?.ToLowerInvariant()); } }