Lightweigth default StreamReader reading nothing

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.

Jon Skeet

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

Foo(new StringReader(""));

If you really need a StreamReader, you could just pass in an empty MemoryStream:

Foo(new StreamReader(new MemoryStream()));


See more on this question at Stackoverflow