Ejemplo n.º 1
0
        public static string SerializeToString(object value, Type type)
        {
            if (value == null)
            {
                return(null);
            }
            if (type == typeof(string))
            {
                return(value as string);
            }

            var writer = StringWriterThreadStatic.Allocate();

            JsvWriter.GetWriteFn(type)(writer, value);
            return(StringWriterThreadStatic.ReturnAndFree(writer));
        }
Ejemplo n.º 2
0
        public string SerializeToString(T value)
        {
            if (value == null)
            {
                return(null);
            }
            if (typeof(T) == typeof(string))
            {
                return(value as string);
            }

            var writer = StringWriterThreadStatic.Allocate();

            JsvWriter <T> .WriteObject(writer, value);

            return(StringWriterThreadStatic.ReturnAndFree(writer));
        }
Ejemplo n.º 3
0
        public static string SerializeToString <T>(T value)
        {
            if (value == null || value is Delegate)
            {
                return(null);
            }
            if (typeof(T) == typeof(object))
            {
                return(SerializeToString(value, value.GetType()));
            }
            if (typeof(T).IsAbstract || typeof(T).IsInterface)
            {
                JsState.IsWritingDynamic = true;
                var result = SerializeToString(value, value.GetType());
                JsState.IsWritingDynamic = false;
                return(result);
            }

            var writer = StringWriterThreadStatic.Allocate();

            JsvWriter <T> .WriteRootObject(writer, value);

            return(StringWriterThreadStatic.ReturnAndFree(writer));
        }