Esempio n. 1
0
        public static string ToJsonString(this IJsonSerializable jsonSerializable)
        {
            if (ReferenceEquals(jsonSerializable, null))
            {
                return(string.Empty);
            }

            var stringBuilder = new StringBuilder();

            using (var writer = JSON.GetWriter(new StringWriter(stringBuilder)))
            {
                try
                {
                    jsonSerializable.ToJson(writer);
                }
                catch (Exception ex)
                {
                    if (Log != null)
                    {
                        Log.WarnFormat(
                            "Unable to serialize component: {0} - {1}",
                            jsonSerializable.GetType().Name,
                            ex.Message
                            );
                    }
                    throw;
                }
            }

            return(stringBuilder.ToString());
        }
Esempio n. 2
0
        public static TRes PackMessage <TRes>(string key, IJsonSerializable obj) where TRes : IDictionary <string, object>
        {
            var result = Activator.CreateInstance <TRes>();

            result.Add(key, obj.ToJson());

            return(result);
        }
Esempio n. 3
0
        protected virtual void WriteValue(IJsonSerializable obj)
        {
            string json = obj.ToJson();

            Debug.Assert(json != null);

            this.WriteCore(json, false);
        }
Esempio n. 4
0
        public static string GetJsonForSymbol(IJsonSerializable serializable)
        {
            if (serializable == null)
            {
                return(null);
            }
            string json = serializable.ToJson();

            return(json);
        }
Esempio n. 5
0
 public static void SerializeToJson(IJsonSerializable data, string path)
 {
     using (FileStream fileStream = new FileStream(path, 2))
     {
         using (StreamWriter streamWriter = new StreamWriter(fileStream))
         {
             streamWriter.Write(data.ToJson());
         }
     }
 }
Esempio n. 6
0
        public static string ToJson(this IJsonSerializable jsonConfig)
        {
            var sb = new StringBuilder();
            var sw = new StringWriter(sb);

            using (var writer = new JsonTextWriter(sw))
            {
                writer.Formatting = Formatting.Indented;
                jsonConfig.ToJson(writer);
            }
            return(sb.ToString());
        }
        /// <summary>
        /// Creates the json request.
        /// </summary>
        /// <returns></returns>
        internal JsonObject CreateJsonRequest()
        {
            IJsonSerializable serializableRequest = this as IJsonSerializable;

            if (serializableRequest == null)
            {
                throw new JsonSerializationNotImplementedException();
            }

            JsonObject jsonRequest = new JsonObject();

            jsonRequest.Add("Header", this.CreateJsonHeaders());
            jsonRequest.Add("Body", serializableRequest.ToJson(service));

            return(jsonRequest);
        }
Esempio n. 8
0
        public static JsonArray FromArray <T>(T[] array)
        {
            int       count     = array.Length;
            JsonArray result    = new JsonArray(count);
            bool      serialize = typeof(IJsonSerializable).IsAssignableFrom(typeof(T));

            for (int i = 0; i < count; i++)
            {
                if (serialize)
                {
                    IJsonSerializable srz = (IJsonSerializable)array[i];
                    result._list.Add(srz.ToJson());
                }
                else
                {
                    result._list.Add(array[i]);
                }
            }
            return(result);
        }
 public void Value(IJsonSerializable s)
 {
     CommaCheck();
     m_w.Write(s.ToJson());
 }
Esempio n. 10
0
 public static object Write(IJsonSerializable val)
 {
     return(val.ToJson());
 }
Esempio n. 11
0
 public static string ToJson(this IJsonSerializable x, bool indent = false)
 {
     return(x.ToJson(new JsonSerializationOptions {
         UseIndentation = indent
     }));
 }
Esempio n. 12
0
 public static string Serialize(IJsonSerializable obj)
 {
     return(JsonSerializer.Serialize(obj.ToJson(), new SerializerConfig()));
 }
Esempio n. 13
0
 public static string Serialize(IJsonSerializable obj, SerializerConfig config)
 {
     return(JsonSerializer.Serialize(obj.ToJson(), config));
 }
Esempio n. 14
0
 public void Put(string key, IJsonSerializable value)
 {
     _dict.Add(key, value.ToJson());
 }
 public static string GetJsonForSymbol(IJsonSerializable serializable)
 {
     if (serializable == null)
         return null;
     string json = serializable.ToJson();
     return json;
 }
Esempio n. 16
0
        protected virtual void WriteValue(IJsonSerializable obj)
        {
            string json = obj.ToJson();

            Debug.Assert(json != null);

            this.WriteCore(json, false);
        }