Search code examples
c#fixed-widthfilehelpers

Conditional record type with FileHelpers


I'm trying to parse a file using the Filehelpers library. My file looks like this:

000001,"A",123,456
000002,"B","ABC","XYZ"
000003,"B","DEF","XYZ"
000004,"B","HIJ","XYZ"

My file contains rows that have different column definitions, where the 'type' of row is defined by the character in the second column. i.e. In the sample above I have an "A" row followed by three "B" rows.

Filehelpers requires that I pass the CLR type used to define a row when I instantiate the file helpers engine, or us the generic version as below.

FileHelperEngine<ARecord> engine = new FileHelperEngine<ARecord>()

This means I'm restricted to a single type to define every row in my file. Is there any way I can parse a file like this and conditionally specify the record type based on a part of the given row?


Solution

  • found it. http://www.filehelpers.com/example_multirecords.html