I wonder how to generate a class holding the values of the fields from a csv file does not establish a rigid number of fields. I read about generating classes using CodeModel, but after completing the program can not be compiled specifically to take a job with a .csv file, it needs to work on the fly. Some files have 22 fields and the other 40. The simplest solution would be to create a class with 50 fields and fill them in a for loop.
Colname1; colname2; colname3...........
Best How To :
Its very hard to create a class at run time when you don't know the number of fields and their data types. You could do two passes though, in the first pass figure out a schema and create classes accordingly and populate in the second pass. Basically you would need to keep track of the field names, their datatypes and a keep a fallback datatype (eg. a subset of records for a particular field might be int and then suddenly you might discover a long).
Personally, I don't think making schemas at runtime provides a very clean solution. A map of maps might have been a better way to deal it. Just my two cents.