Mefhisto1
Mefhisto1

Reputation: 2228

need help using CSVHelper package in Visual Studio 2012

I saw another example here on stackoverflow, the code goes like this:

var csv = new CsvHelper( File.OpenWrite( "some-file.csv" ) );
csv.Writer.WriteRecords( myCustomObjectList );

However, I'm unable to instantiate CsvHelper class, as there isn't one, CsvHelper is a namespace. Is there a way to get the above code working, or did I install something incorrectly? Thanks

Upvotes: 1

Views: 1589

Answers (1)

Nicholas W
Nicholas W

Reputation: 2241

It looks like that example is with an older version of the CsvHelper library. The API changed quite a bit between 1.x and 2.x, and there is no longer a CsvHelper class. You can instantiate the CsvReader and CsvWriter classes directly (or there's a CsvFactory), so the above code could look like this:

var csvWriter = new CsvWriter(new StreamWriter("some-file.csv"));
csvWriter.WriteRecords(myCustomObjectList)

Upvotes: 2

Related Questions