Added jsonconverters to Ellie
This commit is contained in:
parent
2f3e283903
commit
fbfc01c7f3
2 changed files with 28 additions and 0 deletions
14
src/EllieBot/Common/JsonConverters/CultureInfoConverter.cs
Normal file
14
src/EllieBot/Common/JsonConverters/CultureInfoConverter.cs
Normal 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);
|
||||
}
|
14
src/EllieBot/Common/JsonConverters/Rgba32Converter.cs
Normal file
14
src/EllieBot/Common/JsonConverters/Rgba32Converter.cs
Normal 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());
|
||||
}
|
Loading…
Reference in a new issue