public void Import(string filePath, Action<string[]> readAction) { if(readAction == null) throw new ArgumentNullException("readAction"); using(FileStream stream = File.OpenRead(filePath)) { CsvFileReader reader = new CsvFileReader(stream); string[] records; while (reader.ReadRow(out records)) readAction(records); } }
public void ReadRow() { MemoryStream stream = new MemoryStream(); StreamWriter writer = new StreamWriter(stream); const string row = "one,\"t,wo\",\"th\"\"ree\""; writer.WriteLine(row); writer.Flush(); stream.Position = 0; CsvFileReader reader = new CsvFileReader(stream); string[] records; reader.ReadRow(out records); CollectionAssert.AreEqual(new [] {"one", "t,wo", "th\"ree"}, records); }