コード例 #1
0
        public static string SerializeData <T>(IEnumerable <T> data, CsvDataDescriptor descriptor = null, CsvParser.DelimiterType delimiter = CsvParser.DelimiterType.Comma)
        {
            List <List <string> > list = new List <List <string> >();

            if (descriptor == null)
            {
                descriptor = CsvDataDescriptor.CreateDescriptor(typeof(T), null);
            }
            list.Add(descriptor.CreateCsvHeader());
            foreach (T current in data)
            {
                list.Add(CsvSerializer.Serialize(current, descriptor));
            }
            return(CsvParser.ConvertToCsv(list, delimiter));
        }
コード例 #2
0
        public static string SerializeData(IEnumerable <object> data, CsvDataDescriptor descriptor = null, CsvParser.DelimiterType delimiter = CsvParser.DelimiterType.Comma)
        {
            List <List <string> > list = new List <List <string> >();

            if (descriptor == null)
            {
                List <Type> list2 = new List <Type>();
                foreach (object current in data)
                {
                    Type type = current.GetType();
                    if (!list2.Contains(type))
                    {
                        list2.Add(type);
                    }
                }
                descriptor = CsvDataDescriptor.CreateDescriptor(list2, null);
            }
            list.Add(descriptor.CreateCsvHeader());
            foreach (object current2 in data)
            {
                list.Add(CsvSerializer.Serialize(current2, descriptor));
            }
            return(CsvParser.ConvertToCsv(list, delimiter));
        }