Fauna .NET Driver 0.1.0-beta
 
Loading...
Searching...
No Matches
ListDeserializer.cs
Go to the documentation of this file.
1using Fauna.Mapping;
2
3namespace Fauna.Serialization;
4
5internal class ListDeserializer<T> : BaseDeserializer<List<T>>
6{
7 private IDeserializer<T> _elemDeserializer;
8
9 public ListDeserializer(IDeserializer<T> elemDeserializer)
10 {
11 _elemDeserializer = elemDeserializer;
12 }
13
14 public override List<T> Deserialize(MappingContext context, ref Utf8FaunaReader reader)
15 {
16 if (reader.CurrentTokenType != TokenType.StartArray)
17 throw new SerializationException(
18 $"Unexpected token while deserializing into {typeof(List<T>)}: {reader.CurrentTokenType}");
19
20 var lst = new List<T>();
21 while (reader.Read() && reader.CurrentTokenType != TokenType.EndArray)
22 {
23 lst.Add(_elemDeserializer.Deserialize(context, ref reader));
24 }
25
26 return lst;
27 }
28}
T Deserialize(MappingContext context, ref Utf8FaunaReader reader)
TokenType
Enumerates the types of tokens used in Fauna serialization.
Definition TokenType.cs:7