Added jsonconverters to Ellie

This commit is contained in:
Toastie (DCS Team) 2024-03-31 23:45:30 +13:00
parent 2f3e283903
commit fbfc01c7f3
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
2 changed files with 28 additions and 0 deletions

View file

@ -0,0 +1,14 @@
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace EllieBot.Common.JsonConverters;
public class CultureInfoConverter : JsonConverter<CultureInfo>
{
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);
}

View file

@ -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<Rgba32>
{
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());
}