The problem you will see i have is how do I first split the csv into the two lists and second how do i access the header rows correctly in the strongly type object as you see I am using first which will not work correctly.

Its seperating the one line into two classes I need to no how to do
– DaveJan 12 at 12:08

1

So let us understand better your problem. The input file is made of an header and followed by many sales order lines. You need to output a file with an header for each sales order?
– SteveJan 12 at 12:08

HI @Steve yes that is the problem but not a new file I need them in classes so I can manipulate them futher
– DaveJan 12 at 12:08

1

I don't know if FileHelpers could do that. But it seems not necessary to complicate things. If you keep your header instance you can reuse it whenever you need it. At worst create a class with an instance for the Header and an instance for the Order. After reading the file do another loop and initialize the instances of this superclass for every order you have
– SteveJan 12 at 12:13

1 Answer
1

With FileHelpers it is important to avoid using the mapping class for anything other than describing the underlying file structure. Here I suspect you are trying to map directly to a class which is too complex.

A FileHelpers class is just a way of defining the specification of a flat file using C# syntax.

As such, the FileHelpers classes are an unusual type of C# class and you should not try to use accepted OOP principles. FileHelpers should not have properties or methods beyond the ones used by the FileHelpers library.

Think of the FileHelpers class as the 'specification' of your CSV format only. That should be its only role. (This is good practice from a maintenance perspective anyway - if the underlying CSV structure were to change, it is easier to adapt your code).

Then if you need the records in a more 'normal' object, then map the results to something better, that is, a class that encapsulates all the functionality of the Order object rather than the CSVOrder.

So, one way of handling this type of file is to parse the file twice. In the first pass you extract the header records. Something like this: