I have a file reader object that i need to read a file with tables in it. I want to create an object called Table to hold the row and column data from the read file. The trouble is, to read the whole page, i need to have a list of tables (there are more than one in the file). WHat is the best structure of my classes so that i am not exposing the data reader too much and passing it around too much?
My current line of thinking is this:
- Create a class that instantiates a list of tables and pass this class the reader.
- Run the reader and for each new table found, instantiate a new table object and pass along the reference to the reader so it can get row/column info.
Is this the best way to do this kind of task? Or is there a more efficient design to restrict the reader being passed too much? I have to use the using statement and it just doesnt feel right to use it in this nested design
Thanks
You could potentially use the already available
DataTable. There is a little bit of overhead in using them, but it sounds like it would be something easy to work with.You did say that the tables contain different structures. Is there anything in the file that identifies the table changing? This could make it more difficult if there are many ‘tables’ in the same file.
You can simply use a collection of type
DataTableif you want to have a list of them around. I suppose you could create your own class for this if your design warrants that.and a sample method of how it may be used:
Here is a link to a CSV parser if you are interested in going that route, since you said it is comma-separated.