Exemple #1
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();

            if (typeof(T) == typeof(string))
            {
                JsonUtils.WriteString(writer, value as string);
            }
            else
            {
                JsonWriter <T> .WriteRootObject(writer, value);
            }
            return(StringWriterThreadStatic.ReturnAndFree(writer));
        }
Exemple #2
0
        public static string SerializeToCsv <T>(IEnumerable <T> records)
        {
            var writer = StringWriterThreadStatic.Allocate();

            writer.WriteCsv(records);
            return(StringWriterThreadStatic.ReturnAndFree(writer));
        }
        public string SerializeToString(T value)
        {
            if (value == null)
            {
                return(null);
            }
            if (typeof(T) == typeof(object) || typeof(T).IsAbstract || typeof(T).IsInterface)
            {
                if (typeof(T).IsAbstract || typeof(T).IsInterface)
                {
                    JsState.IsWritingDynamic = true;
                }
                var result = JsonSerializer.SerializeToString(value, value.GetType());
                if (typeof(T).IsAbstract || typeof(T).IsInterface)
                {
                    JsState.IsWritingDynamic = false;
                }
                return(result);
            }

            var writer = StringWriterThreadStatic.Allocate();

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

            return(StringWriterThreadStatic.ReturnAndFree(writer));
        }
        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));
        }
        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));
        }