public void WriteAll(string file, List <KeyValuePair <string, int> > records) { Integrity.CheckFile(file); using (TextWriter textWriter = File.CreateText(file)) { var csvWriter = new CsvWriter(textWriter); foreach (var item in records) { csvWriter.WriteRecord(item); } } }
public List <Record> ReadAll(string file) { Integrity.CheckFile(file); try { using (var textReader = File.OpenText(file)) { return(new CsvReader(textReader).GetRecords <Record>().ToList()); } } catch (FileNotFoundException fex) { throw fex; } }
public void WriteAll(string file, IOrderedEnumerable <KeyValuePair <string, string> > records) { Integrity.CheckFile(file); using (TextWriter textWriter = File.CreateText(file)) { /* * Turns out CsvWriter is buggy. * * var csv = new CsvWriter(textWriter); * csv.WriteRecords(list); */ foreach (var record in records.ToList()) { if (record.Value != null) { textWriter.WriteLine(record.Value); } } } }