Ejemplo n.º 1
0
 /// <summary>
 /// 将对象转换为使用文本并写入到流中。
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="value"></param>
 /// <param name="writer"></param>
 public void Serialize <T>(T value, JsonWriter writer)
 {
     using (var ser = new JsonSerialize(this, writer, Option))
     {
         ser.Serialize(value);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 将对象转换为使用文本并写入到流中。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value"></param>
        /// <param name="writer"></param>
        public void Serialize <T>(T value, JsonWriter writer)
        {
            var ser = new JsonSerialize(this, writer, Option);

            using (var context = new JsonConvertContext())
            {
                ser.Serialize(value);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 将对象转换为使用文本表示。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value">要序列化的对象。</param>
        /// <returns>表示对象的 Json 文本。</returns>
        public string Serialize <T>(T value)
        {
            using var sw     = new StringWriter(CultureInfo.InvariantCulture);
            using var writer = new JsonWriter(sw);
            using var ser    = new JsonSerialize(this, writer, Option);
            if (Option.Indent)
            {
                writer.Indent = 4;
            }

            ser.Serialize(value);
            return(sw.ToString());
        }
Ejemplo n.º 4
0
        public string Serialize <T>(T value)
        {
            using (var sw = new StringWriter(CultureInfo.InvariantCulture))
                using (var writer = new JsonWriter(sw))
                    using (var ser = new JsonSerialize(this, writer, Option))
                        using (var context = new JsonConvertContext())
                        {
                            if (Option.Indent)
                            {
                                writer.Indent = 4;
                            }

                            ser.Serialize(value);
                            return(sw.ToString());
                        }
        }