Exemplo n.º 1
0
        public static string SerializeToString <T>(T value)
        {
            var writer = StringWriterThreadStatic.Allocate();

            GetWriteFn(value.GetType())(writer, value);
            return(StringWriterThreadStatic.ReturnAndFree(writer));
        }
Exemplo n.º 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 (value is string)
            {
                return(value as string);
            }

            var writer = StringWriterThreadStatic.Allocate();

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

            return(StringWriterThreadStatic.ReturnAndFree(writer));
        }
Exemplo n.º 4
0
        public static string SerializeToString <T>(T value)
        {
            if (value == null)
            {
                return(null);
            }
            if (typeof(T) == typeof(string))
            {
                return(value as string);
            }

            var writer = StringWriterThreadStatic.Allocate();

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

            return(StringWriterThreadStatic.ReturnAndFree(writer));
        }
Exemplo n.º 5
0
        public static string SerializeObjectToString(object obj, Options options = null)
        {
            if (obj == null)
            {
                return(null);
            }
            options = options ?? s_DefaultOptions;
            var writer = StringWriterThreadStatic.Allocate();

            new Serializer(options).SerializeObjectInternal(obj, writer);
            var json = StringWriterThreadStatic.ReturnAndFree(writer);

            if (options.PrettyPrint)
            {
                return(StringExtension.PrettyPrint(json));
            }
            else
            {
                return(json);
            }
        }