Example #1
0
        public static void SerializeToStream(object value, Type type, Stream stream)
        {
            var writer = new DirectStreamWriter(stream, UTF8Encoding);

            JsonWriter.GetWriteFn(type)(writer, value);
            writer.Flush();
        }
Example #2
0
        public static void SerializeToStream <T>(T value, Stream stream)
        {
            if (value == null)
            {
                return;
            }
            if (typeof(T) == typeof(object))
            {
                SerializeToStream(value, value.GetType(), stream);
            }
            else if (typeof(T).IsAbstract() || typeof(T).IsInterface())
            {
                JsState.IsWritingDynamic = false;
                SerializeToStream(value, value.GetType(), stream);
                JsState.IsWritingDynamic = true;
            }
            else
            {
                var writer = new DirectStreamWriter(stream, UTF8Encoding);
                JsonWriter <T> .WriteRootObject(writer, value);

                writer.Flush();
            }
        }