1using System.Collections;
6internal class ListSerializer<T> : BaseSerializer<List<T>>
8 private readonly ISerializer<T> _elemSerializer;
10 public ListSerializer(ISerializer<T> elemSerializer)
12 _elemSerializer = elemSerializer;
15 public override List<T> Deserialize(
MappingContext context, ref Utf8FaunaReader reader)
17 if (reader.CurrentTokenType ==
TokenType.StartPage)
18 throw new SerializationException(
19 $
"Unexpected token while deserializing into {typeof(List<T>)}: {reader.CurrentTokenType}");
21 var wrapInList = reader.CurrentTokenType !=
TokenType.StartArray;
23 var lst =
new List<T>();
27 lst.Add(_elemSerializer.Deserialize(context, ref reader));
31 while (reader.Read() && reader.CurrentTokenType !=
TokenType.EndArray)
33 lst.Add(_elemSerializer.Deserialize(context, ref reader));
40 public override void Serialize(
MappingContext ctx, Utf8FaunaWriter w,
object? o)
48 if (o.GetType().IsGenericType &&
49 o.GetType().GetGenericTypeDefinition() == typeof(List<>) ||
50 o.GetType().GetGenericTypeDefinition() == typeof(IEnumerable))
53 foreach (
object? elem
in (IEnumerable)o)
55 _elemSerializer.Serialize(ctx, w, elem);
A class representing the mapping context to be used during serialization and deserialization.
string UnsupportedSerializationTypeMessage(Type type)
TokenType
Enumerates the types of tokens used in Fauna serialization.