I\'m using CSVHelper to read in lots of data
I\'m wondering if it\'s possible to read the last n columns in and transpose them to a list
You don't actually need to define the column names beforehand, you can get them from the FieldHeaders property. So in a more dynamic version of Neil's answer you could define your Mapper as such:
public sealed class PersonMap : CsvClassMap {
public override void CreateMap() {
Map(m => m.FirstName).Name("FirstName").Index(0);
Map(m => m.LastName).Name("LastName").Index(1);
Map(m => m.Attributes).ConvertUsing(row =>
(row as CsvReader)?.FieldHeaders
.Where(header => header.StartsWith("Attribute"))
.Select(header => row.GetField(header))
.Where(value => !string.IsNullOrWhiteSpace(value))
.ToList()
);
}
}