37 lines
972 B
C#
37 lines
972 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace Questionable.Model.Questing.Converter;
|
|
|
|
public sealed class ElementIdListConverter : JsonConverter<List<ElementId>>
|
|
{
|
|
public override List<ElementId> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
{
|
|
if (reader.TokenType != JsonTokenType.StartArray)
|
|
{
|
|
throw new JsonException();
|
|
}
|
|
reader.Read();
|
|
List<ElementId> list = new List<ElementId>();
|
|
while (reader.TokenType != JsonTokenType.EndArray)
|
|
{
|
|
if (reader.TokenType == JsonTokenType.Number)
|
|
{
|
|
list.Add(new QuestId(reader.GetUInt16()));
|
|
}
|
|
else
|
|
{
|
|
list.Add(ElementId.FromString(reader.GetString() ?? throw new JsonException()));
|
|
}
|
|
reader.Read();
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public override void Write(Utf8JsonWriter writer, List<ElementId> value, JsonSerializerOptions options)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|