1using System.Collections;
8internal class ListSerializer<T> : BaseSerializer<List<T>>
10 private readonly ISerializer<T> _elemSerializer;
12 public ListSerializer(ISerializer<T> elemSerializer)
14 _elemSerializer = elemSerializer;
17 public override List<FaunaType> GetSupportedTypes() =>
new List<FaunaType> {
FaunaType.Array, FaunaType.Null };
19 public override List<T> Deserialize(
MappingContext ctx, ref Utf8FaunaReader reader)
21 if (reader.CurrentTokenType ==
TokenType.StartPage)
23 $
"Unexpected token while deserializing into {typeof(List<T>)}: {reader.CurrentTokenType}");
25 var wrapInList = reader.CurrentTokenType !=
TokenType.StartArray;
27 var lst =
new List<T>();
31 lst.Add(_elemSerializer.Deserialize(ctx, ref reader));
35 while (reader.Read() && reader.CurrentTokenType !=
TokenType.EndArray)
37 lst.Add(_elemSerializer.Deserialize(ctx, ref reader));
44 public override void Serialize(
MappingContext ctx, Utf8FaunaWriter w,
object? o)
52 if (o.GetType().IsGenericType &&
53 o.GetType().GetGenericTypeDefinition() == typeof(List<>) ||
54 o.GetType().GetGenericTypeDefinition() == typeof(IEnumerable))
57 foreach (
object? elem
in (IEnumerable)o)
System.ArgumentException ArgumentException
Represents error that occur during serialization and deserialization of Fauna data.
A class representing the mapping context to be used during serialization and deserialization.
string UnsupportedSerializationTypeMessage(Type type)
A helper to build an unsupported serialization type exception message.
void Serialize(MappingContext ctx, Utf8FaunaWriter writer, object? o)
Serializes the provided object into the Utf8FaunaWriter.
FaunaType
An enum representing possible Fauna types.
TokenType
Enumerates the types of tokens used in Fauna serialization.