CsvHelper
CsvHelper copied to clipboard
If Name is configured in map it cannot be skipped on reading file.
Feature description and justification We'd like to use one map-class both for reading and writing. Thus, we configured mapping both with indexes and names and it works great, when users upload and download files in strict format.
But, if they change headers in some columns (i.e. add some description text to column header) the file isn't mapped on reading and there is no setting that'll change this behavior to "map by indexes only".
We tried to use PrepareHeaderForMatch, but it's called also for the names themself, which looks a little bit weird.
The solution we'd like to see in CsvHelper We'd like to have a setting, i.e. "map by indexes only". This option'll say csvreader to ignore column headers on reading files and map data only by column indexes.
I think I can just change it so that if a name is specified, it will always use a name for reading. If you know the index when reading, there wouldn't be a reason to specify the name anyways.
Sorry, that won't actually solve your problem. Maybe there should be a delegate to get the index so users can do whatever they need to. PrepareHeaderForMatch is too narrow.
The behavior I would prefer, when I declare both an Index and a Name attribute is that I would want the name validation to happen first and if the name isn't found then it should fall back to index. This allows the user to submit a malformed header as long as they didn't rearrange the columns. Or they can put them in the wrong order if the header names match.
I guess you're saying I should just go by index and not define name?
@A9G-Data-Droid I don't think you would want it to do that automatically. It might work for your situation, but if someone else has a situation where they are getting the headers in the wrong order and one or more header names don't match, it could end up mapping the wrong data with no exception thrown.
@AltruCoder If we just use Index without name checking the same problem exists. Any field with a matching type will be loading wrong data with no exception thrown. So header matching is ideal.