示例#1
0
 public static void SerializeToWriter <T>(T value, TextWriter writer)
 {
     if (value == null)
     {
         return;
     }
     if (typeof(T) == typeof(string))
     {
         writer.Write(value);
         return;
     }
     CsvSerializer <T> .WriteObject(writer, value);
 }
示例#2
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));
        }
示例#3
0
        public static string SerializeToString <T>(T value)
        {
            if (value == null)
            {
                return(null);
            }
            if (typeof(T) == typeof(string))
            {
                return(value as string);
            }

            var sb = new StringBuilder();

            using (var writer = new StringWriter(sb, CultureInfo.InvariantCulture))
            {
                CsvSerializer <T> .WriteObject(writer, value);
            }
            return(sb.ToString());
        }
示例#4
0
        public static void InitAot <T>()
        {
            CsvSerializer <T> .WriteFn();

            CsvSerializer <T> .WriteObject(null, null);

            CsvWriter <T> .Write(null, default(IEnumerable <T>));

            CsvWriter <T> .WriteRow(null, default(T));

            CsvWriter <T> .WriteObject(null, default(IEnumerable <T>));

            CsvWriter <T> .WriteObjectRow(null, default(IEnumerable <T>));

            CsvReader <T> .ReadRow(null);

            CsvReader <T> .ReadObject(null);

            CsvReader <T> .ReadObjectRow(null);

            CsvReader <T> .ReadStringDictionary(null);
        }
示例#5
0
 public static string ToCsv <T>(this T obj)
 {
     return(CsvSerializer.SerializeToString(obj));
 }