diff --git a/src/EllieBot/Common/JsonConverters/CultureInfoConverter.cs b/src/EllieBot/Common/JsonConverters/CultureInfoConverter.cs new file mode 100644 index 0000000..0c26f15 --- /dev/null +++ b/src/EllieBot/Common/JsonConverters/CultureInfoConverter.cs @@ -0,0 +1,14 @@ +using System.Globalization; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace EllieBot.Common.JsonConverters; + +public class CultureInfoConverter : JsonConverter +{ + public override CultureInfo Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + => new(reader.GetString() ?? "en-US"); + + public override void Write(Utf8JsonWriter writer, CultureInfo value, JsonSerializerOptions options) + => writer.WriteStringValue(value.Name); +} \ No newline at end of file diff --git a/src/EllieBot/Common/JsonConverters/Rgba32Converter.cs b/src/EllieBot/Common/JsonConverters/Rgba32Converter.cs new file mode 100644 index 0000000..ef619a6 --- /dev/null +++ b/src/EllieBot/Common/JsonConverters/Rgba32Converter.cs @@ -0,0 +1,14 @@ +using SixLabors.ImageSharp.PixelFormats; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace EllieBot.Common.JsonConverters; + +public class Rgba32Converter : JsonConverter +{ + public override Rgba32 Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + => Rgba32.ParseHex(reader.GetString()); + + public override void Write(Utf8JsonWriter writer, Rgba32 value, JsonSerializerOptions options) + => writer.WriteStringValue(value.ToHex()); +} \ No newline at end of file