Пример #1
0
        public static void SerializeObject <T>(T value, Stream stream, Encoding encoding, JsonFormatterOptions options)
        {
            var hGCache = CharsPool.Rent();

            SerializeObject(value, hGCache, options);

            hGCache.WriteTo(stream, encoding);

            CharsPool.Return(hGCache);
        }
Пример #2
0
        /// <summary>
        /// 异步将 JSON 字符串反序列化到指定的数据写入器中。
        /// </summary>
        /// <param name="textReader">JSON 字符串读取器</param>
        /// <param name="dataWriter">数据写入器</param>
        public async Task DeserializeToAsync(TextReader textReader, IDataWriter dataWriter)
        {
            var hGCache = CharsPool.Rent();

            await hGCache.ReadFromAsync(textReader);

            DeserializeTo(hGCache, dataWriter);

            CharsPool.Return(hGCache);
        }
Пример #3
0
        public async Task SerializeAsync <T>(T value, TextWriter textWriter)
        {
            var hGCache = CharsPool.Rent();

            Serialize(value, hGCache);

            await hGCache.WriteToAsync(textWriter);

            CharsPool.Return(hGCache);
        }
Пример #4
0
        public static async Task SerializeObjectAsync <T>(T value, Stream stream, Encoding encoding, JsonFormatterOptions options)
        {
            var hGCache = CharsPool.Rent();

            SerializeObject(value, hGCache, options);

            await hGCache.WriteToAsync(stream, encoding);

            CharsPool.Return(hGCache);
        }
Пример #5
0
        public async Task SerializeAsync <T>(T value, Stream stream, Encoding encoding)
        {
            var hGCache = CharsPool.Rent();

            Serialize(value, hGCache);

            await hGCache.WriteToAsync(stream, encoding);

            CharsPool.Return(hGCache);
        }
Пример #6
0
        public static async Task SerializeObjectAsync <T>(T value, TextWriter textWriter, JsonFormatterOptions options)
        {
            var hGCache = CharsPool.Rent();

            SerializeObject(value, hGCache, options);

            await hGCache.WriteToAsync(textWriter);

            CharsPool.Return(hGCache);
        }
Пример #7
0
        public static string SerializeObject <T>(T value)
        {
            var hGCache = CharsPool.Rent();

            SerializeObject(value, hGCache);

            var str = hGCache.ToStringEx();

            CharsPool.Return(hGCache);

            return(str);
        }
Пример #8
0
        public static object DeserializeObject(Stream stream, Encoding encoding, Type type, JsonFormatterOptions options)
        {
            var hGCache = CharsPool.Rent();

            hGCache.ReadFrom(stream, encoding);

            var value = DeserializeObject(hGCache, type, options);

            CharsPool.Return(hGCache);

            return(value);
        }
Пример #9
0
        public static object DeserializeObject(TextReader textReader, Type type, JsonFormatterOptions options)
        {
            var hGCache = CharsPool.Rent();

            hGCache.ReadFrom(textReader);

            var value = DeserializeObject(hGCache, type, options);

            CharsPool.Return(hGCache);

            return(value);
        }
Пример #10
0
        public async Task <T> DeserializeAsync <T>(Stream stream, Encoding encoding)
        {
            var hGCache = CharsPool.Rent();

            await hGCache.ReadFromAsync(stream, encoding);

            var value = Deserialize <T>(hGCache);

            CharsPool.Return(hGCache);

            return(value);
        }
Пример #11
0
        public async Task <object> DeserializeAsync(TextReader textReader, Type type)
        {
            var hGCache = CharsPool.Rent();

            await hGCache.ReadFromAsync(textReader);

            var value = Deserialize(hGCache, type);

            CharsPool.Return(hGCache);

            return(value);
        }
Пример #12
0
        public static async Task <T> DeserializeObjectAsync <T>(Stream stream, Encoding encoding, JsonFormatterOptions options)
        {
            var hGCache = CharsPool.Rent();

            await hGCache.ReadFromAsync(stream, encoding);

            var value = DeserializeObject <T>(hGCache);

            CharsPool.Return(hGCache);

            return(value);
        }
Пример #13
0
        public static async Task <object> DeserializeObjectAsync(TextReader textReader, Type type, JsonFormatterOptions options)
        {
            var hGCache = CharsPool.Rent();

            await hGCache.ReadFromAsync(textReader);

            var value = DeserializeObject(hGCache, type, options);

            CharsPool.Return(hGCache);

            return(value);
        }
Пример #14
0
        public async Task <T> DeserializeAsync <T>(TextReader textReader)
        {
            var hGCache = CharsPool.Rent();

            await hGCache.ReadFromAsync(textReader);

            var value = Deserialize <T>(hGCache);

            CharsPool.Return(hGCache);

            return(value);
        }
Пример #15
0
        public static async Task <object> DeserializeObjectAsync(Stream stream, Encoding encoding, Type type)
        {
            var hGCache = CharsPool.Rent();

            await hGCache.ReadFromAsync(stream, encoding);

            var value = DeserializeObject(hGCache, type);

            CharsPool.Return(hGCache);

            return(value);
        }
Пример #16
0
        public static string SerializeObject <T>(T value, JsonFormatterOptions options)
        {
            var hGCache = CharsPool.Rent();

            SerializeObject(value, hGCache, options);

            var str = hGCache.ToStringEx();

            CharsPool.Return(hGCache);

            return(str);
        }
Пример #17
0
        public static T DeserializeObject <T>(TextReader textReader)
        {
            var hGCache = CharsPool.Rent();

            hGCache.ReadFrom(textReader);

            var value = DeserializeObject <T>(hGCache);

            CharsPool.Return(hGCache);

            return(value);
        }
Пример #18
0
        public static T DeserializeObject <T>(Stream stream, Encoding encoding)
        {
            var hGCache = CharsPool.Rent();

            hGCache.ReadFrom(stream, encoding);

            var value = DeserializeObject <T>(hGCache);

            CharsPool.Return(hGCache);

            return(value);
        }
Пример #19
0
        public static IJsonReader CreateJsonReader(Stream stream, Encoding encoding)
        {
            var hGCache = CharsPool.Rent();

            hGCache.ReadFrom(stream, encoding);

            var jsonReader = CreateJsonReader(hGCache);

            CharsPool.Return(hGCache);

            return(jsonReader);
        }
Пример #20
0
        public static IJsonReader CreateJsonReader(TextReader textReader)
        {
            var hGCache = CharsPool.Rent();

            hGCache.ReadFrom(textReader);

            var jsonReader = CreateJsonReader(hGCache);

            CharsPool.Return(hGCache);

            return(jsonReader);
        }
Пример #21
0
        public static void SerializeObject <T>(T value, TextWriter textWriter, JsonFormatterOptions options)
        {
            var hGCache = CharsPool.Rent();

            if ((options & ReferenceOptions) != 0)
            {
                var jsonSerializer = new JsonSerializer <JsonSerializeModes.ReferenceMode>(options, hGCache, DefaultMaxDepth)
                {
                    References = new JsonReferenceWriter()
                };

                if ((options & JsonFormatterOptions.Indented) != 0)
                {
                    jsonSerializer.IndentedChars  = DefaultIndentedChars;
                    jsonSerializer.LineBreakChars = DefaultLineCharsBreak;
                    jsonSerializer.MiddleChars    = DefaultMiddleChars;
                }

                ValueInterface <T> .WriteValue(jsonSerializer, value);

                jsonSerializer.Flush();
            }
            else if ((options & ComplexOptions) != 0)
            {
                var jsonSerializer = new JsonSerializer <JsonSerializeModes.ComplexMode>(options, hGCache, DefaultMaxDepth);

                if ((options & JsonFormatterOptions.Indented) != 0)
                {
                    jsonSerializer.IndentedChars  = DefaultIndentedChars;
                    jsonSerializer.LineBreakChars = DefaultLineCharsBreak;
                    jsonSerializer.MiddleChars    = DefaultMiddleChars;
                }

                ValueInterface <T> .WriteValue(jsonSerializer, value);

                jsonSerializer.Flush();
            }
            else
            {
                var jsonSerializer = new JsonSerializer <DefaultSerializeMode>(options, hGCache, DefaultMaxDepth);

                ValueInterface <T> .WriteValue(jsonSerializer, value);

                jsonSerializer.Flush();
            }

            hGCache.WriteTo(textWriter);

            CharsPool.Return(hGCache);
        }
Пример #22
0
        public static void SerializeObject <T>(T value, TextWriter textWriter)
        {
            var hGCache = CharsPool.Rent();

            var jsonSerializer = new JsonSerializer <DefaultSerializeMode>(hGCache, DefaultMaxDepth)
            {
                textWriter = textWriter
            };

            ValueInterface <T> .WriteValue(jsonSerializer, value);

            jsonSerializer.Flush();

            hGCache.WriteTo(textWriter);

            CharsPool.Return(hGCache);
        }