Пример #1
0
        /// <summary>
        /// Map the items to a csv text.
        /// </summary>
        /// <param name="items">The items to map</param>
        /// <param name="errors">The errors to collect.</param>
        public void MapToFile(IList <T> items, IDictionary <string, string> excludeProps, string path, IErrors errors)
        {
            var props = new List <KeyValuePair <string, PropertyInfo> >();

            MapperHelper.GetProps(typeof(T), string.Empty, props);

            List <List <object> > records = new List <List <object> >();

            foreach (T item in items)
            {
                var rec = new List <object>();
                MapperHelper.MapFrom(item, excludeProps, props, (colname, val) =>
                {
                    if (val != null)
                    {
                        rec.Add(val);
                    }
                    else
                    {
                        rec.Add("");
                    }
                });
                records.Add(rec);
            }
            List <string> cols = new List <string>();

            foreach (var pair in props)
            {
                cols.Add(pair.Key);
            }

            CsvWriter writer = new CsvWriter(@"c:\temp\conference.csv", records, ",", cols, false, false, "\"", Environment.NewLine, false);

            writer.Write();
            writer.Dispose();
        }