public static String CaptureOutput(Action Action, bool Capture = true)
{
if (Capture)
{
var OldOut = Console.Out;
var StringWriter = new StringWriter();
try
{
Console.SetOut(StringWriter);
Action();
}
finally
{
Console.SetOut(OldOut);
}
try
{
return StringWriter.ToString();
}
catch
{
return "";
}
}
else
{
Action();
return "";
}
}
}