dimka87il
dimka87il

Reputation: 95

FileHelperEngine order of columns

hi i am using FileHelperEngine for parsing csv files.

FileHelperEngine csvEngine = new FileHelperEngine(typeof (Model));
Model[] lines= csvEngine.ReadFile(fileName) as Model[];

this works fine if the columns order matchh the order of the properties in Model object all the csv files have header at the first line. but i have propblem when the header order is not the same as the Model properties...

how can it work if the order of the csv columns is not the same order as the Model object ?

Upvotes: 0

Views: 949

Answers (1)

shamp00
shamp00

Reputation: 11326

You should use two classes, a Model which is a FileHelpers record class and which is just the spec of your CSV file. It should only contain public fields (not properties) and the fields should be in the same order as in the CSV file. (FileHelpers record classes should not be considered as normal C# classes that should follow best coding practices; rather it is just a syntax for describing import files' structure.)

Then once you've read the file into a Model[] array, then enumerate through it to map the fields to your second class ModelObject which is not a FileHelpers class and which can have the properties in any order.

Upvotes: 2

Related Questions