Using CSV Helper, I'm wondering if there is there a way to dynamically create class properties based on whether or not the corresponding column is found in my csv file.
The file I'm working with may or may not have a column titled 'ACTIVITY'. If upon reading it, there is no such column, is there a way to omit the creation of the Activity property all together?
// csv properties
public class Pr530CsvHandler
{
public string Company { get; set; }
public string Name { get; set; }
// other expected properties...
public string Activity { get; set; } //<-- don't create if there is no corresponding column in CSV
}
// map
public sealed class Pr530Map : ClassMap<Pr530CsvHandler>
{
public Pr530Map()
{
Map(m => m.Company).Name("COMPANY").Optional();
Map(m => m.Name).Name("NAME").Optional();
// other mapped headers...
Map(m => m.Activity).Name("ACTIVITY").Optional(); // this one may not exist in CSV
}
}