I have CSV file that has multiples columns with the same header name. I am using CsvHelper library. I want to collect their row values into one List but I am collecting first row value as many times I have header specified and not collecting from another index position. ex. COLUMN COLUMN Test1 Test2 Test3 Test4 I expect that my list has two elements first with value Test1,Test2 and second one with values Test3,Test4 but I first row has values Test1,Test1 and second Test3,Test3.
This is the mapping for this column
Map(m => m.COLUMN).ConvertUsing(row =>
(row as CsvReader)?.FieldHeaders
.Where(header => header.StartsWith("COLUMN"))
.Select(header => row.GetField<string>(header))
.Where(value => !string.IsNullOrWhiteSpace(value))
.ToList()
);
Can this be done with mapping? If I change Column names to COLUMN1 and COLUMN2 this works but that is not the solution for my problem.