public static string SerializeToString <T>(T value)
        {
            var writer = StringWriterManager.Allocate();

            GetWriteFn(value.GetType())(writer, value);
            return(StringWriterManager.ReturnAndFree(writer));
        }
Exemple #2
0
        public string SerializeToString(T value)
        {
            if (value == null)
            {
                return(null);
            }
            if (typeof(T) == typeof(string))
            {
                return(value as string);
            }
            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 = StringWriterManager.Allocate();

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

            return(StringWriterManager.ReturnAndFree(writer));
        }
Exemple #3
0
        public static string SerializeToCsv <T>(IEnumerable <T> records)
        {
            var writer = StringWriterManager.Allocate();

            writer.WriteCsv(records);
            return(StringWriterManager.ReturnAndFree(writer));
        }
        /// <summary>Converts the <see cref="DateTimeOffset"/> to its JSON string representation using the <see cref="DateFormatHandling"/> specified.</summary>
        /// <param name="value">The value to convert.</param>
        /// <param name="format">The format the date will be converted to.</param>
        /// <returns>A JSON string representation of the <see cref="DateTimeOffset"/>.</returns>
        public static string ToString(DateTimeOffset value, DateFormatHandling format)
        {
            //using (StringWriter writer = StringUtils.CreateStringWriter(64))
            var writer = StringWriterManager.Allocate();

            writer.Write('"');
            DateTimeUtils.WriteDateTimeOffsetString(writer, value, format, null, CultureInfo.InvariantCulture);
            writer.Write('"');

            return(StringWriterManager.ReturnAndFree(writer));
        }
        /// <summary>Converts the <see cref="DateTime"/> to its JSON string representation using the <see cref="DateFormatHandling"/> specified.</summary>
        /// <param name="value">The value to convert.</param>
        /// <param name="format">The format the date will be converted to.</param>
        /// <param name="timeZoneHandling">The time zone handling when the date is converted to a string.</param>
        /// <returns>A JSON string representation of the <see cref="DateTime"/>.</returns>
        public static string ToString(DateTime value, DateFormatHandling format, DateTimeZoneHandling timeZoneHandling)
        {
            var updatedDateTime = DateTimeUtils.EnsureDateTime(value, timeZoneHandling);

            //using (StringWriter writer = StringUtils.CreateStringWriter(64))
            var writer = StringWriterManager.Allocate();

            writer.Write('"');
            DateTimeUtils.WriteDateTimeString(writer, updatedDateTime, format, null, CultureInfo.InvariantCulture);
            writer.Write('"');

            return(StringWriterManager.ReturnAndFree(writer));
        }
        public string SerializeToString(T value)
        {
            if (value == null)
            {
                return(null);
            }
            if (value is string)
            {
                return(value as string);
            }

            var writer = StringWriterManager.Allocate();

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

            return(StringWriterManager.ReturnAndFree(writer));
        }
Exemple #7
0
        public static string SerializeToString <T>(T value)
        {
            if (value == null)
            {
                return(null);
            }
            if (typeof(T) == typeof(string))
            {
                return(value as string);
            }

            var writer = StringWriterManager.Allocate();

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

            return(StringWriterManager.ReturnAndFree(writer));
        }