You can create a state machine that tracks peek-mode vs regular-mode. Maybe something like this (maybe just drop them all into a single file called Peeker.cs or something like that):
public sealed class Peeker { internal readonly PeekMode PEEKING; internal readonly NormalMode NORMAL; private ReadState _state; public Peeker() { PEEKING = new PeekMode(this); NORMAL = new NormalMode(this);
Kind of redundant, but good.
To use it, you simply do the following:
Peeker p = new Peeker(); . . . SomeDataReaderType dr = SomeCommandType.ExecuteReader(); . . . // To peek object[] myDataRow = p.OnRead(dr, true); // or not to peek object[] myDataRow = p.OnRead(dr, false);
Then do what you need to do with your string. Perhaps a better way than using an array of objects, but you get the point.
Good luck
Jason down
source share