public override void WriteJson(JsonWriter writer, QueryExpression value, JsonSerializer serializer)
        {
            IReferenceResolver resolver = serializer.Context.Context as IReferenceResolver;

            writer.WriteStartObject();

            writer.WritePropertyName("$id");
            serializer.Serialize(writer, new Guid(resolver.GetReference(null, value)));

            writer.WritePropertyName("$type");
            serializer.Serialize(writer, nameof(QueryExpression));

            writer.WritePropertyName("Consumer");
            serializer.Serialize(writer, null);

            writer.WritePropertyName("Parameters");
            if (value.Parameters == null)
            {
                serializer.Serialize(writer, null);
            }
            else if (value.Parameters.Count == 0)
            {
                writer.WriteStartArray();
                writer.WriteEndArray();
            }
            else
            {
                writer.WriteStartArray();
                foreach (ParameterExpression parameter in value.Parameters)
                {
                    serializer.Serialize(writer, parameter, typeof(ParameterExpression));
                }
                writer.WriteEndArray();
            }

            writer.WritePropertyName("Expressions");
            if (value.Expressions == null)
            {
                serializer.Serialize(writer, null);
            }
            else if (value.Expressions.Count == 0)
            {
                writer.WriteStartArray();
                writer.WriteEndArray();
            }
            else
            {
                writer.WriteStartArray();
                foreach (HermesModel model in value.Expressions)
                {
                    serializer.Serialize(writer, model, model.GetType());
                }
                writer.WriteEndArray();
            }

            writer.WriteEndObject();
        }
Пример #2
0
        public override void WriteJson(JsonWriter writer, JoinExpression value, JsonSerializer serializer)
        {
            IReferenceResolver resolver = serializer.Context.Context as IReferenceResolver;

            writer.WriteStartObject();

            writer.WritePropertyName("$id");
            serializer.Serialize(writer, new Guid(resolver.GetReference(null, value)));

            writer.WritePropertyName("$type");
            serializer.Serialize(writer, nameof(JoinExpression));

            writer.WritePropertyName("Consumer");
            if (value.Consumer == null)
            {
                serializer.Serialize(writer, null);
            }
            else
            {
                serializer.Serialize(writer, value.Consumer, value.Consumer.GetType());
            }

            writer.WritePropertyName("Name");
            serializer.Serialize(writer, value.Name);

            writer.WritePropertyName("Alias");
            serializer.Serialize(writer, value.Alias);

            writer.WritePropertyName("Entity");
            serializer.Serialize(writer, value.Entity);

            writer.WritePropertyName("Hint");
            serializer.Serialize(writer, value.Hint);

            writer.WritePropertyName("JoinType");
            serializer.Serialize(writer, value.JoinType);

            writer.WritePropertyName("ON");
            if (value.ON == null)
            {
                serializer.Serialize(writer, null);
            }
            else
            {
                serializer.Serialize(writer, value.ON, value.ON.GetType());
            }

            writer.WriteEndObject();
        }
Пример #3
0
        public override void WriteJson(JsonWriter writer, Property value, JsonSerializer serializer)
        {
            IReferenceResolver resolver = serializer.Context.Context as IReferenceResolver;

            writer.WriteStartObject();

            writer.WritePropertyName("$id");
            serializer.Serialize(writer, new Guid(resolver.GetReference(null, value)));

            writer.WritePropertyName("$type");
            serializer.Serialize(writer, nameof(Property));

            writer.WritePropertyName("identity");
            serializer.Serialize(writer, value.Identity.ToString());

            writer.WriteEndObject();
        }
        public override void WriteJson(JsonWriter writer, ParameterExpression value, JsonSerializer serializer)
        {
            IReferenceResolver resolver = serializer.Context.Context as IReferenceResolver;

            writer.WriteStartObject();

            writer.WritePropertyName("$id");
            serializer.Serialize(writer, new Guid(resolver.GetReference(null, value)));

            writer.WritePropertyName("$type");
            serializer.Serialize(writer, nameof(ParameterExpression));

            writer.WritePropertyName("Consumer");
            if (value.Consumer == null)
            {
                serializer.Serialize(writer, null);
            }
            else
            {
                serializer.Serialize(writer, value.Consumer, value.Consumer.GetType());
            }

            writer.WritePropertyName("Name");
            serializer.Serialize(writer, value.Name);

            writer.WritePropertyName("Type");
            serializer.Serialize(writer, value.Type);

            writer.WritePropertyName("Value");
            if (value.Value == null)
            {
                serializer.Serialize(writer, null);
            }
            else
            {
                serializer.Serialize(writer, value.Value, value.Value.GetType());
            }

            writer.WriteEndObject();
        }
        public override void Write(Utf8JsonWriter writer, DummyAssembly value, JsonSerializerOptions options)
        {
            bool   isNew = false;
            string id    = _resolver.GetReference(value, ref isNew);

            if (!isNew)
            {
                writer.WriteStartObject();
                writer.WriteString("$ref", id);
                writer.WriteEndObject();
                return;
            }

            Type type = value.GetType();

            writer.WriteStartObject();
            writer.WriteString("$id", id);
            writer.WriteString("$type", _binder.GetTypeCode(type));
            foreach (PropertyInfo info in type.GetProperties())
            {
                WriteProperty(writer, value, info, options);
            }
            writer.WriteEndObject();
        }
    public string GetReference(object context, object value)
    {
        var representative = GetOrAddRepresentativeObject(value);

        return(defaultResolver.GetReference(context, representative));
    }
Пример #7
0
        public override void WriteJson(JsonWriter writer, SelectStatement value, JsonSerializer serializer)
        {
            IReferenceResolver resolver = serializer.Context.Context as IReferenceResolver;

            writer.WriteStartObject();

            writer.WritePropertyName("$id");
            serializer.Serialize(writer, new Guid(resolver.GetReference(null, value)));

            writer.WritePropertyName("$type");
            serializer.Serialize(writer, nameof(SelectStatement));

            writer.WritePropertyName("Consumer");
            if (value.Consumer == null)
            {
                serializer.Serialize(writer, null);
            }
            else
            {
                serializer.Serialize(writer, value.Consumer, value.Consumer.GetType());
            }

            writer.WritePropertyName("Name");
            serializer.Serialize(writer, value.Name);

            writer.WritePropertyName("Alias");
            serializer.Serialize(writer, value.Alias);

            writer.WritePropertyName("Entity");
            serializer.Serialize(writer, value.Entity, typeof(Entity));

            writer.WritePropertyName("Hint");
            serializer.Serialize(writer, value.Hint);

            writer.WritePropertyName("FROM");
            if (value.FROM == null)
            {
                serializer.Serialize(writer, null);
            }
            else if (value.FROM.Count == 0)
            {
                writer.WriteStartArray();
                writer.WriteEndArray();
            }
            else
            {
                writer.WriteStartArray();
                foreach (TableExpression model in value.FROM)
                {
                    serializer.Serialize(writer, model, model.GetType());
                }
                writer.WriteEndArray();
            }

            writer.WritePropertyName("SELECT");
            if (value.SELECT == null)
            {
                serializer.Serialize(writer, null);
            }
            else if (value.SELECT.Count == 0)
            {
                writer.WriteStartArray();
                writer.WriteEndArray();
            }
            else
            {
                writer.WriteStartArray();
                foreach (PropertyExpression model in value.SELECT)
                {
                    serializer.Serialize(writer, model, model.GetType());
                }
                writer.WriteEndArray();
            }

            writer.WritePropertyName("WHERE");
            if (value.WHERE == null)
            {
                serializer.Serialize(writer, null);
            }
            else
            {
                serializer.Serialize(writer, value.WHERE, value.WHERE.GetType());
            }

            writer.WriteEndObject();
        }
        public override void WriteJson(JsonWriter writer, BooleanFunction value, JsonSerializer serializer)
        {
            IReferenceResolver resolver = serializer.Context.Context as IReferenceResolver;

            if (value is BooleanOperator)
            {
                writer.WriteStartObject();

                writer.WritePropertyName("$id");
                serializer.Serialize(writer, new Guid(resolver.GetReference(null, value)));

                writer.WritePropertyName("$type");
                serializer.Serialize(writer, nameof(BooleanOperator));

                writer.WritePropertyName("Consumer");
                if (value.Consumer == null)
                {
                    serializer.Serialize(writer, null);
                }
                else
                {
                    serializer.Serialize(writer, value.Consumer, value.Consumer.GetType());
                }

                writer.WritePropertyName("Name");
                serializer.Serialize(writer, value.Name);

                BooleanOperator source = (BooleanOperator)value;
                writer.WritePropertyName("Operands");
                if (source.Operands == null)
                {
                    serializer.Serialize(writer, null);
                }
                else if (source.Operands.Count == 0)
                {
                    writer.WriteStartArray();
                    writer.WriteEndArray();
                }
                else
                {
                    writer.WriteStartArray();
                    foreach (BooleanFunction item in source.Operands)
                    {
                        serializer.Serialize(writer, item, item.GetType());
                    }
                    writer.WriteEndArray();
                }

                writer.WriteEndObject();
            }
            else if (value is ComparisonOperator)
            {
                writer.WriteStartObject();

                writer.WritePropertyName("$id");
                serializer.Serialize(writer, new Guid(resolver.GetReference(null, value)));

                writer.WritePropertyName("$type");
                serializer.Serialize(writer, nameof(ComparisonOperator));

                writer.WritePropertyName("Consumer");
                if (value.Consumer == null)
                {
                    serializer.Serialize(writer, null);
                }
                else
                {
                    serializer.Serialize(writer, value.Consumer, value.Consumer.GetType());
                }

                writer.WritePropertyName("Name");
                serializer.Serialize(writer, value.Name);

                ComparisonOperator source = (ComparisonOperator)value;
                writer.WritePropertyName("LeftExpression");
                if (source.LeftExpression == null)
                {
                    serializer.Serialize(writer, null);
                }
                else
                {
                    serializer.Serialize(writer, source.LeftExpression, source.LeftExpression.GetType());
                }

                writer.WritePropertyName("RightExpression");
                if (source.RightExpression == null)
                {
                    serializer.Serialize(writer, null);
                }
                else
                {
                    serializer.Serialize(writer, source.RightExpression, source.RightExpression.GetType());
                }

                writer.WriteEndObject();
            }
        }