[英]How to check if Console.Out was set using my TextWriter
我将控制台更改为自定义TextWriter类(TextBoxStreamWriter)。 我想检查是否使用我的writer实例设置了Console.Out(因为其他类可能已经更改了它,等等)。
样品:
// "TextBoxStreamWriter : TextWriter" is a custom class that writes to a textbox...
TextBoxStreamWriter myWriter = new TextBoxStreamWriter(someTextBoxInstance);
Console.SetOut(myWriter);
bool check = Console.Out == myWriter;
// But check is false! I need to know if .Out was set from my custom class or not.
可以预期,请查看Console.SetOut
源代码: http : //referencesource.microsoft.com/#mscorlib/system/console.cs,2d6029756ecc3409 。 它将您的文本SyncTextWriter
包装在SyncTextWriter
。
我认为您必须使用反射来查看包装的类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.