Fauna v10 .NET/C# Driver 1.0.1
 
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 List<FaunaType> GetSupportedTypes() => _inner.GetSupportedTypes();
15
16 public override T? Deserialize(MappingContext ctx, ref Utf8FaunaReader reader)
17 {
18 if (reader.CurrentTokenType == TokenType.Null)
19 {
20 return default(T);
21 }
22
23 return _inner.Deserialize(ctx, ref reader);
24 }
25
26 public override void Serialize(MappingContext context, Utf8FaunaWriter writer, object? o)
27 {
28 _inner.Serialize(context, writer, (T?)o);
29 }
30}
A class representing the mapping context to be used during serialization and deserialization.
void Serialize(MappingContext ctx, Utf8FaunaWriter writer, object? o)
Serializes the provided object into the Utf8FaunaWriter.
new T Deserialize(MappingContext ctx, ref Utf8FaunaReader reader)
Consumes all or some of a Utf8FaunaReader and returns an instance of T .
object? ISerializer. Deserialize(MappingContext ctx, ref Utf8FaunaReader reader)
Consumes or partially consumes the provided reader and deserializes into a result.
void ISerializer. Serialize(MappingContext context, Utf8FaunaWriter writer, object? o)
Serializes the provided object onto the Utf8FaunaWriter
TokenType
Enumerates the types of tokens used in Fauna serialization.
Definition TokenType.cs:7