/// <summary> /// Stops the capture of output, restores the normal Console.Out stream, and /// returns a string /// </summary> /// <returns>A string, containing all the output since capturing started</returns> public string StopOutputCapturing() { string sOut = "<NO OUTPUT CAPTURING IN PROGRESS>"; if (capturedOut != null) { sOut = capturedOut.ToString(); Console.SetOut(originalOut); capturedOut = null; } return sOut; }
/// <summary> /// This method will set up everything so that Console.out output /// is captured to a string /// </summary> public void StartOutputCapturing() { originalOut = Console.Out; capturedOut = new TeeWriter(new StringWriter(), originalOut); Console.SetOut(capturedOut); }