Beispiel #1
0
        protected override void ReadObjectProperties(ref Utf8JsonReader reader, VariableQueryArgumentList result, Dictionary <string, Property> properties, JsonSerializerOptions options)
        {
            reader.AssertProperty(nameof(VariableQueryArgumentList.ElementType));
            var elementTypeInfo = reader.Read <TypeInfo>(options) ?? throw reader.CreateException($"{nameof(VariableQueryArgumentList.ElementType)} must not be null.");

            void SetResult(ref Utf8JsonReader reader, List <object?>?values = null)
            {
                reader.AssertEndObject();
                result.ElementType = elementTypeInfo;
                result.Values      = values ?? new List <object?>();
            }

            reader.Advance();
            if (reader.TokenType == JsonTokenType.Null)
            {
                SetResult(ref reader);
                return;
            }

            if (reader.TokenType != JsonTokenType.StartArray)
            {
                throw reader.CreateException($"Expected array");
            }

            bool TryReadNextItem(ref Utf8JsonReader reader, out object?value)
            {
                if (!reader.TryRead(elementTypeInfo, options, out value))
                {
                    if (reader.TokenType == JsonTokenType.EndArray)
                    {
                        return(false);
                    }

                    throw reader.CreateException("Unexpected token structure.");
                }

                return(true);
            }

            var values = new List <object?>();

            while (TryReadNextItem(ref reader, out object?value))
            {
                values.Add(value);
            }

            SetResult(ref reader, values);
        }
        protected override void ReadObjectProperties(ref Utf8JsonReader reader, TExpression result, Dictionary <string, Property> properties, JsonSerializerOptions options)
        {
            if (result is ConstantExpression constantExpression)
            {
                reader.AssertProperty(nameof(ConstantExpression.Type));
                var typeInfo = reader.Read <TypeInfo>(options);
                constantExpression.Type = typeInfo ?? throw reader.CreateException($"{nameof(ConstantExpression.Type)} must not be null.");

                reader.Advance();
                if (reader.IsProperty(ValueTypePropertyName))
                {
                    typeInfo = reader.Read <TypeInfo>(options);
                    reader.Advance();
                }

                reader.AssertProperty(nameof(ConstantExpression.Value), false);
                var value = reader.Read(typeInfo, options);
                constantExpression.Value = value;

                reader.AssertEndObject();
            }
            else
            {
                base.ReadObjectProperties(ref reader, result, properties, options);
            }
        }
        protected override void ReadObjectProperties(ref Utf8JsonReader reader, VariableQueryArgument result, Dictionary <string, Property> properties, JsonSerializerOptions options)
        {
            reader.AssertProperty(nameof(VariableQueryArgument.Type));
            var typeInfo = reader.Read <TypeInfo>(options) ?? throw reader.CreateException($"{nameof(VariableQueryArgument.Type)} must not be null.");

            reader.AssertProperty(nameof(VariableQueryArgument.Value));
            var value = reader.Read(typeInfo, options);

            reader.AssertEndObject();

            result.CheckNotNull(nameof(result)).Type = typeInfo;
            result.Value = value;
        }