public void Write(ref WriteStack state, Utf8JsonWriter writer) { Debug.Assert(ShouldSerialize); if (state.Current.CollectionEnumerator != null) { // Forward the setter to the value-based JsonPropertyInfo. JsonPropertyInfo propertyInfo = ElementClassInfo.PolicyProperty; propertyInfo.WriteEnumerable(ref state, writer); } else { int originalDepth = writer.CurrentDepth; OnWrite(ref state.Current, writer); if (originalDepth != writer.CurrentDepth) { ThrowHelper.ThrowJsonException_SerializationConverterWrite(state.PropertyPath, ConverterBase.ToString()); } } }
public void WriteDictionary(ref WriteStack state, Utf8JsonWriter writer) { Debug.Assert(ShouldSerialize); int originalDepth = writer.CurrentDepth; OnWriteDictionary(ref state.Current, writer); if (originalDepth != writer.CurrentDepth) { ThrowHelper.ThrowJsonException_SerializationConverterWrite(state.PropertyPath, ConverterBase.ToString()); } }
private void VerifyRead(JsonTokenType tokenType, int depth, long bytesConsumed, ref ReadStack state, ref Utf8JsonReader reader) { switch (tokenType) { case JsonTokenType.StartArray: if (reader.TokenType != JsonTokenType.EndArray) { ThrowHelper.ThrowJsonException_SerializationConverterRead(reader, state.JsonPath, ConverterBase.ToString()); } else if (depth != reader.CurrentDepth) { ThrowHelper.ThrowJsonException_SerializationConverterRead(reader, state.JsonPath, ConverterBase.ToString()); } // Should not be possible to have not read anything. Debug.Assert(bytesConsumed < reader.BytesConsumed); break; case JsonTokenType.StartObject: if (reader.TokenType != JsonTokenType.EndObject) { ThrowHelper.ThrowJsonException_SerializationConverterRead(reader, state.JsonPath, ConverterBase.ToString()); } else if (depth != reader.CurrentDepth) { ThrowHelper.ThrowJsonException_SerializationConverterRead(reader, state.JsonPath, ConverterBase.ToString()); } // Should not be possible to have not read anything. Debug.Assert(bytesConsumed < reader.BytesConsumed); break; default: // Reading a single property value. if (reader.BytesConsumed != bytesConsumed) { ThrowHelper.ThrowJsonException_SerializationConverterRead(reader, state.JsonPath, ConverterBase.ToString()); } // Should not be possible to change token type. Debug.Assert(reader.TokenType == tokenType); break; } }