forked from EllieBotDevs/elliebot
14 lines
512 B
C#
14 lines
512 B
C#
|
using System.Globalization;
|
||
|
using System.Text.Json;
|
||
|
using System.Text.Json.Serialization;
|
||
|
|
||
|
namespace Ellie.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);
|
||
|
}
|