Fauna v10 .NET/C# Driver 1.0.0
 
Loading...
Searching...
No Matches
NullableStructSerializer.cs
Go to the documentation of this file.
1using Fauna.Mapping;
2
3namespace Fauna.Serialization;
4
5internal class NullableStructSerializer<T> : BaseSerializer<T?> where T : struct
6{
7 private readonly ISerializer<T> _inner;
8
9 public NullableStructSerializer(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 return reader.CurrentTokenType == TokenType.Null ? new T?() : _inner.Deserialize(ctx, ref reader);
19 }
20
21 public override void Serialize(MappingContext context, Utf8FaunaWriter writer, object? o)
22 {
23 _inner.Serialize(context, writer, (T?)o);
24 }
25}
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.
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