Questionable/Questionable.Model/Questing/Converter/ElementIdConverter.cs

22 lines
694 B
C#
Raw Permalink Normal View History

2024-08-03 20:17:18 +00:00
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Questionable.Model.Questing.Converter;
public sealed class ElementIdConverter : JsonConverter<ElementId>
2024-08-03 20:17:18 +00:00
{
public override ElementId Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.Number)
return new QuestId(reader.GetUInt16());
else
return ElementId.FromString(reader.GetString() ?? throw new JsonException());
2024-08-03 20:17:18 +00:00
}
public override void Write(Utf8JsonWriter writer, ElementId value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
}