8internal class RefSerializer<T> :
BaseSerializer<Ref<T>> where T : notnull
10 private readonly BaseRefSerializer<T> _baseRefSerializer;
14 _baseRefSerializer =
new BaseRefSerializer<T>(docSerializer);
19 return (
Ref<T>)_baseRefSerializer.Deserialize(context, ref reader);
24 _baseRefSerializer.Serialize(context, writer, o);
28internal class NamedRefSerializer<T> :
BaseSerializer<NamedRef<T>> where T : notnull
30 private readonly BaseRefSerializer<T> _baseRefSerializer;
32 public NamedRefSerializer(
ISerializer docSerializer)
34 _baseRefSerializer =
new BaseRefSerializer<T>(docSerializer);
39 return (
NamedRef<T>)_baseRefSerializer.Deserialize(context, ref reader);
44 _baseRefSerializer.Serialize(context, writer, o);
48internal class BaseRefSerializer<T> :
BaseSerializer<BaseRef<T>> where T : notnull
54 _docSerializer = docSerializer;
59 return reader.CurrentTokenType
switch
61 TokenType.StartRef => DeserializeRefInternal(
new BaseRefBuilder<T>(), context, ref reader),
62 TokenType.StartDocument => DeserializeDocument(
new BaseRefBuilder<T>(), context, ref reader),
64 $
"Unexpected token while deserializing into Ref: {reader.CurrentTokenType}")
95 while (reader.Read() && reader.CurrentTokenType !=
TokenType.EndRef)
97 if (reader.CurrentTokenType !=
TokenType.FieldName)
99 $
"Unexpected token while deserializing into NamedRef: {reader.CurrentTokenType}");
101 string fieldName = reader.GetString()!;
106 builder.Id = reader.GetString();
109 builder.Name = reader.GetString();
112 builder.Collection = reader.GetModule();
115 builder.Cause = reader.GetString();
118 builder.Exists = reader.GetBoolean();
122 $
"Unexpected field while deserializing into Ref: {fieldName}");
126 return builder.
Build();
132 while (reader.Read() && reader.CurrentTokenType !=
TokenType.EndDocument)
134 if (reader.CurrentTokenType !=
TokenType.FieldName)
136 $
"Unexpected token while deserializing into NamedRef: {reader.CurrentTokenType}");
138 string fieldName = reader.GetString()!;
143 builder.Id = reader.GetString();
146 builder.Name = reader.GetString();
149 builder.Collection = reader.GetModule();
151 if (_docSerializer is not IPartialDocumentSerializer cs)
153 throw new SerializationException($
"Serializer {_docSerializer.GetType().Name} must implement IPartialDocumentSerializer interface.");
157 builder.Doc = (T?)cs.DeserializeDocument(context, builder.
Id, builder.
Name, builder.
Collection, ref reader);
162 if (reader.CurrentTokenType ==
TokenType.EndDocument)
break;
165 return builder.
Build();
A class representing the mapping context to be used during serialization and deserialization.