I have an instance of System.IO.TextWriter. It may be passed in from System.Console. Any way to find out it is Console without causing exception? I tried this but not compiled:
if (_myWriter as System.Console != null ) // error compiling
I guess I have to use type checking instead of boxing?
You could try something like IsConsoleOut below:
Unfortunately, this isn’t fool proof, as someone could create their own TextReader directly around the Console output stream (using Console.OpenStandardOutput() to get the stream), and the above function would fail to identify it, but provided the TextWriter has always come from Console.Out it should work – I think!