I am in the need of a default
StreamReader reading nothing without throwing any exceptions.
How can I efficiently construct such an object?
Edit Specifically, if I read from the
StreamReader object with
ReadLine I would like to get
null and no exception.
Ideally, I would suggest using
TextReader as your abstraction level - it's rarely necessary to depend on
StreamReader directly, as messing around with the underlying stream is generally a bad idea anyway.
If you have code that takes a
TextReader, you could use
If you really need a
StreamReader, you could just pass in an empty
Foo(new StreamReader(new MemoryStream()));
See more on this question at Stackoverflow