I have a method that takes either a StringReader
instance (reading from the clipboard) or a StreamReader
instance (reading from a file) and, at present, casts either one as a TextReader
instance.
I need it to 'pre-read' some of the source input, then reset the cursor back to the start. I do not necessarily have the original filename. How to I do this?
There is mention of the Seek
method of System.IO.Stream
but this is not implemented in TextReader
, although it is in StreamReader
through the Basestream
property. However StringReader
does not have a BaseStream
property
Look for it first around on the exterior of your machine, especially along the bottom edge near the ground. An AC's reset button is typically red and visible, so it should be easy to spot. If you don't see a reset button on the outside, it could be located inside the unit behind the service panel.
Once you've established there is power, you can restart your AC using the reset button. Some air conditioning systems have a reset switch, which is a small, red button. Typically, the button will be on the outdoor unit.
After you've turned the system back on, it will take a bit of time for the air conditioner's internal circuitry to reset. It usually takes about 30 minutes, so sit tight until then.
It depends on the TextReader
. If it's a StreamReader
, you can use:
sr.BaseStream.Position = 0; sr.DiscardBufferedData();
(Assuming the underlying stream is seekable, of course.)
Other implementations of TextReader
may not have a concept of "rewinding", in the same way that IEnumerable<T>
doesn't. In many ways you can think of TextReader
as a glorified IEnumerable<char>
. It has methods to read whole chunks of data at a time, read lines etc, but it's fundamentally a "forward reading" type.
EDIT: I don't believe StringReader
supports any sort of rewinding - you'd be better off recreating the StringReader
from the original string, if you can. If that's not feasible, you could always create your own TextReader
class which proxies all the "normal" calls to another StringReader
, but recreates that proxy instance when it needs to.
If it is a StreamReader
, and if that stream supports seeking, then:
reader.BaseStream.Seek(0, SeekOrigin.Begin); reader.DiscardBufferedData();
However, this is not possible on arbitrary TextReader
s. You could perhaps read all of it as a string, then you can use StringReader
repeatedly?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With