phatcher / CsvReader

Extended version of Sebastian Lorien's fast CSV Reader
MIT License
300 stars 102 forks source link

GetFieldIndex returns -1 when setting custom columns and specifying hasHeaders = true #43

Open janis-veinbergs opened 7 years ago

janis-veinbergs commented 7 years ago

Given I use hasHeaders: true for CsvReader constructor and want to manually specify columns with correct types, _fieldHeaderIndexes doesn't get populated that results in broken GetFieldIndex method.

Because given hasHeaders = true the _fieldHeaderIndexes gets populated (line 1592) only when no Columns have been added before.

My workaround is to initialize CsvReader with hasHeaders: false and then use csv.ReadNextRecord() before while loop: while (csv.ReadNextRecord()) { ... }

BrianVallelunga commented 7 years ago

I just ran into this bug as well. Thanks for providing a workaround.

phatcher commented 6 years ago

@janis-veinbergs @BrianVallelunga Can you check the current code base, there are some fixes around this