Copy Source | Copy HTML
- using System;
- using System.IO;
-
- namespace RedirectIO
- {
- public class OutToMemory : IDisposable
- {
- private StreamWriter memoryOutput;
- private TextWriter oldOutput;
- private MemoryStream stream;
-
- public OutToMemory(string outFileName)
- {
- oldOutput = Console.Out;
- stream = new MemoryStream();
- memoryOutput = new StreamWriter(stream);
- memoryOutput.AutoFlush = true;
- Console.SetOut(memoryOutput);
- }
-
- public String Finish()
- {
- Console.SetOut(oldOutput);
- stream.Seek( 0, SeekOrigin.Begin);
- String result;
- // тут как-то надо вытащить из stream данные и запихать их в result
- memoryOutput.Close();
- return result;
- }
- }
- }
-