I'm trying to write a program that loads a CSV file into a custom class I've created. To do this I'm using the following library: http://joshclose.github.io/CsvHelper/#mapping
I've written my entity class, as follows:
public class BreakthroughCampaignEntity
{
public string ConstituentId { get; set; }
public string F2F { get; set; }
public string GiftStatus { get; set; }
public string Title1 { get; set; }
public string FirstName { get; set; }
public string Surname { get; set; }
public string PreferredAddress { get; set; }
public string PreferredSuburb { get; set; }
public string PreferredEmailNumber { get; set; }
public string PreferrredHomeNumber { get; set; }
public string PreferredWorkNumber { get; set; }
public string PreferrredMobileNumber { get; set; }
public string GiftAmount { get; set; }
public DateTime GiftNextTransactionDueDate { get; set; }
public DateTime GiftSpecificAttributesPledgeGiftSignUpDate { get; set; }
}
And my index mapping:
public class BreakthroughCampaignIndexMap : CsvClassMap<BreakthroughCampaignEntity>
{
/// <summary>
/// Creates a map by matching the CSV indexes to our entity class
/// </summary>
public override void CreateMap()
{
Map(m => m.ConstituentId).Index(0).Default("Unknown");
Map(m => m.F2F).Index(1).Default("Unknown");
Map(m => m.GiftStatus).Index(2).Default("Unknown");
Map(m => m.Title1).Index(3).Default("Unknown");
Map(m => m.FirstName).Index(4).Default("Unknown");
Map(m => m.Surname).Index(5).Default("Unknown");
Map(m => m.PreferredAddress).Index(6).Default("Unknown");
Map(m => m.PreferredSuburb).Index(7).Default("Unknown");
Map(m => m.PreferredEmailNumber).Index(8).Default("Unknown");
Map(m => m.PreferrredHomeNumber).Index(9).Default("Unknown");
Map(m => m.PreferredWorkNumber).Index(10).Default("Unknown");
Map(m => m.PreferrredMobileNumber).Index(11).Default("Unknown");
Map(m => m.GiftAmount).Index(12).Default("Unknown");
Map(m => m.GiftNextTransactionDueDate).Index(13);
Map(m => m.GiftSpecificAttributesPledgeGiftSignUpDate).Index(14);
}
}
I've also installed the CSV helper library via the package manager console, to ensure I have the latest version.
Unfortunately however, when I go to load my CSV, using the following:
var csv = new CsvReader(TextFileToProcess.Text.ToString());
var processedFile = csv.GetRecords<BreakthroughCampaignEntity>();
As referenced in this StackExchange post (answer by Josh Close) I receive the following error below TextFileToProcess.Text.ToString():
Cannot resolve constructor 'CsvReader(string)', candidates are: CsvReader(CsvHelper.ICsvParser) (in class CsvReader) CsvReader(System.IO.TextReader) (in class CsvReader)
I've also tried using:
var csv = new CsvReader(File.OpenRead(TextFileToProcess.Text.ToString()));
Which provides the same error.
I'd love to understand what this means, not just how to fix it! I have some gaps in my knowledge which means although this error seems to indicate how to fix the problem, I don't understand what it's telling me.