private static void WriteData <T>(IEnumerable <T> values, string fileName, TextWriter stream, CsvFileDescription fileDescription) { FieldMapper <T> fm = new FieldMapper <T>(fileDescription, fileName, true); CsvStream cs = new CsvStream(null, stream, fileDescription.SeparatorChar, fileDescription.IgnoreTrailingSeparatorChar); List <string> row = new List <string>(); // If first line has to carry the field names, write the field names now. if (fileDescription.FirstLineHasColumnNames) { fm.WriteNames(row); cs.WriteRow(row, fileDescription.QuoteAllFields); } foreach (T obj in values) { // Convert obj to row fm.WriteObject(obj, row); cs.WriteRow(row, fileDescription.QuoteAllFields); } }