/// <summary> /// Writes opening { and 'type' property /// </summary> /// <param name="writer">JSON writer</param> private void writeStartObject(JsonTextWriter writer) { writer.WriteStartObject(); writer.WritePropertyName("type"); writer.WriteValue(GetTypeString(this.Tag)); }
/// <summary> /// Writes the Field class in JSON format /// </summary> /// <param name="writer">JSON writer</param> /// <param name="names">list of named schemas already written</param> /// <param name="encspace">enclosing namespace for the field</param> protected internal void writeJson(JsonTextWriter writer, SchemaNames names, string encspace) { writer.WriteStartObject(); JsonHelper.writeIfNotNullOrEmpty(writer, "name", this.Name); JsonHelper.writeIfNotNullOrEmpty(writer, "doc", this.Documentation); if (null != this.DefaultValue) { writer.WritePropertyName("default"); this.DefaultValue.WriteTo(writer, null); } if (null != this.Schema) { writer.WritePropertyName("type"); Schema.WriteJson(writer, names, encspace); } if (null != this.Props) this.Props.WriteJson(writer); if (null != aliases) { writer.WritePropertyName("aliases"); writer.WriteStartArray(); foreach (string name in aliases) writer.WriteValue(name); writer.WriteEndArray(); } writer.WriteEndObject(); }
/// <summary> /// Returns the canonical JSON representation of this schema. /// </summary> /// <returns>The canonical JSON representation of this schema.</returns> public override string ToString() { System.IO.StringWriter sw = new System.IO.StringWriter(); Arch.CMessaging.Client.Newtonsoft.Json.JsonTextWriter writer = new Arch.CMessaging.Client.Newtonsoft.Json.JsonTextWriter(sw); if (this is PrimitiveSchema || this is UnionSchema) { writer.WriteStartObject(); writer.WritePropertyName("type"); } WriteJson(writer, new SchemaNames(), null); // stand alone schema, so no enclosing name space if (this is PrimitiveSchema || this is UnionSchema) writer.WriteEndObject(); return sw.ToString(); }