I'm merging some of my cvs reading code into a single class, and I'm thinking of just making it override streamreader. However, I want to keep the class private values I added (delimiter, recordcount, etc) and be able to close and reopen the file.
The reason I need to be able to is to do a quick pass to determine various things such as the delimiter, whether there are embedded line breaks in the data, actual record count, field count, etc.
Obviously I can't use using (streamreader sr = new streamreadder(filename)) because that will destroy the object at the end but can I close the file and reopen it? Can I do cvsstreamclass sr = new cvsstreamclass(filename), and then sr.close() and sr.open()? I understand that streamreader seek has problems so I probably shouldn't just use that.
Or am I going about this all wrong and should I just pass in the streamreader object to a class that handles the parsing and whatnot??
btw, I'm not looking at switching to an opensource cvs class or other library. I've already got a lot of this code written, and it works. No need to suggest that.
A CSV parser is not a StreamReader
. The two are not related and there should not be an inheritance relationship.
Your CsvReader
class should have a StreamReader
member. You can the set and manipulate that member however you like. For example, you can close the existing reader and create a new one at any time.