Ejemplo n.º 1
0
        /// <summary>
        /// Writes the JSON representation of an object.
        /// </summary>
        /// <param name="writer">
        /// The <see cref="JsonWriter"/> to write to.
        /// </param>
        /// <param name="value">
        /// The object to write.
        /// </param>
        /// <param name="serializer">
        /// The calling serializer.
        /// </param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            writer.WriteStartObject();

            var dependencies = (Dictionary <string, Dependency>)value;

            foreach (string key in dependencies.Keys)
            {
                writer.WritePropertyName(key);

                Dependency dependency = dependencies[key];
                if (dependency.SchemaDependency != null)
                {
                    SchemaWriter.WriteSchema(writer, dependency.SchemaDependency);
                }
                else if (dependency.PropertyDependencies != null)
                {
                    writer.WriteStartArray();
                    foreach (string arrayElement in dependency.PropertyDependencies)
                    {
                        writer.WriteValue(arrayElement);
                    }

                    writer.WriteEndArray();
                }
            }

            writer.WriteEndObject();
        }
        /// <summary>
        /// Writes the JSON representation of an object.
        /// </summary>
        /// <param name="writer">
        /// The <see cref="JsonWriter"/> to write to.
        /// </param>
        /// <param name="value">
        /// The object to write.
        /// </param>
        /// <param name="serializer">
        /// The calling serializer.
        /// </param>
        /// <remarks>
        /// An <see cref="AdditionalProperties"/> object can hold either a JSON schema or
        /// a Boolean value. If <see cref="AdditionalProperties.Schema"/> is non-null,
        /// write it out; otherwise write out the Boolean value.
        /// </remarks>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var additionalProperties = (AdditionalProperties)value;

            if (additionalProperties.Schema != null)
            {
                SchemaWriter.WriteSchema(writer, additionalProperties.Schema);
            }
            else
            {
                JValue v = (JValue)JToken.FromObject(additionalProperties.Allowed);
                v.WriteTo(writer);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Writes the JSON representation of an object.
        /// </summary>
        /// <param name="writer">
        /// The <see cref="JsonWriter"/> to write to.
        /// </param>
        /// <param name="value">
        /// The object to write.
        /// </param>
        /// <param name="serializer">
        /// The calling serializer.
        /// </param>
        /// <remarks>
        /// An <see cref="AdditionalProperties"/> object can hold either a JSON schema or
        /// a Boolean value. If <see cref="AdditionalProperties.Schema"/> is non-null,
        /// write it out; otherwise write out the Boolean value.
        /// </remarks>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var items = (Items)value;

            if (items.SingleSchema)
            {
                SchemaWriter.WriteSchema(writer, items.Schema);
            }
            else
            {
                writer.WriteStartArray();
                foreach (JsonSchema schema in items.Schemas)
                {
                    SchemaWriter.WriteSchema(writer, items.Schema);
                }

                writer.WriteEndArray();
            }
        }