コード例 #1
0
ファイル: JsonHelper.cs プロジェクト: sdgdsffdsfff/hermes.net
 /// <summary>
 /// Writes JSON property name and value if value is not null
 /// </summary>
 /// <param name="writer">JSON writer</param>
 /// <param name="key">property name</param>
 /// <param name="value">property value</param>
 internal static void writeIfNotNullOrEmpty(JsonTextWriter writer, string key, string value)
 {
     if (string.IsNullOrEmpty(value)) return;
     writer.WritePropertyName(key);
     writer.WriteValue(value);
 }
コード例 #2
0
ファイル: Schema.cs プロジェクト: sdgdsffdsfff/hermes.net
 /// <summary>
 /// Writes schema object 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 of the schema</param>
 protected internal virtual void WriteJson(JsonTextWriter writer, SchemaNames names, string encspace)
 {
     writeStartObject(writer);
     WriteJsonFields(writer, names, encspace);
     if (null != this.Props) Props.WriteJson(writer);
     writer.WriteEndObject();
 }
コード例 #3
0
ファイル: Field.cs プロジェクト: sdgdsffdsfff/hermes.net
        /// <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();
        }
コード例 #4
0
ファイル: Schema.cs プロジェクト: sdgdsffdsfff/hermes.net
 /// <summary>
 /// Default implementation for writing schema properties 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 of the schema</param>
 protected internal virtual void WriteJsonFields(JsonTextWriter writer, SchemaNames names, string encspace)
 {
 }
コード例 #5
0
ファイル: Schema.cs プロジェクト: sdgdsffdsfff/hermes.net
 /// <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));
 }
コード例 #6
0
ファイル: Schema.cs プロジェクト: sdgdsffdsfff/hermes.net
        /// <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();
        }
コード例 #7
0
ファイル: Protocol.cs プロジェクト: sdgdsffdsfff/hermes.net
        /// <summary>
        /// Writes Protocol in JSON format
        /// </summary>
        /// <returns>JSON string</returns>
        public override string ToString()
        {
            using (System.IO.StringWriter sw = new System.IO.StringWriter())
            {
				using (Arch.CMessaging.Client.Newtonsoft.Json.JsonTextWriter writer = new Arch.CMessaging.Client.Newtonsoft.Json.JsonTextWriter(sw))
                {
                    #if(DEBUG)
					writer.Formatting = Arch.CMessaging.Client.Newtonsoft.Json.Formatting.Indented;
                    #endif

                    WriteJson(writer, new SchemaNames());
                    writer.Flush();
                    return sw.ToString();
                }
            }
        }
コード例 #8
0
 /// <summary>
 /// Writes primitive schema in JSON format
 /// </summary>
 /// <param name="w"></param>
 /// <param name="names"></param>
 /// <param name="encspace"></param>
 protected internal override void WriteJson(JsonTextWriter w, SchemaNames names, string encspace)
 {
     w.WriteValue(Name);
 }