Fauna v10 .NET/C# Driver 0.2.0-beta
 
Loading...
Searching...
No Matches
NullableSerializer.cs
Go to the documentation of this file.
1using Fauna.Mapping;
2
3namespace Fauna.Serialization;
4
5internal class NullableSerializer<T> : BaseSerializer<T?>
6{
7 private readonly ISerializer<T> _inner;
8
9 public NullableSerializer(ISerializer<T> inner)
10 {
11 _inner = inner;
12 }
13
14 public override T? Deserialize(MappingContext context, ref Utf8FaunaReader reader)
15 {
16 if (reader.CurrentTokenType == TokenType.Null)
17 {
18 return default(T);
19 }
20
21 return _inner.Deserialize(context, ref reader);
22 }
23
24 public override void Serialize(MappingContext context, Utf8FaunaWriter writer, object? o)
25 {
26 DynamicSerializer.Singleton.Serialize(context, writer, o);
27 }
28}
A class representing the mapping context to be used during serialization and deserialization.
TokenType
Enumerates the types of tokens used in Fauna serialization.
Definition TokenType.cs:7