C#:检查窗体是否形成

Ste*_*ger 0 .net c# vb.net asp.net

如何在运行时检查C#应用程序是Windows应用程序还是控制台应用程序?

我想写一个通用输出库(在控制台应用程序时输出到文本框或控制台).
出于这个原因,如果我可以检查它是否是一个asp应用程序也是有用的.

Dan*_*ger 6

I think you may be attacking the problem in the wrong way. Without knowing more about what you are doing here is what I'd suggest:

Create an interface called something like IOutputWriter with a Write(...) method. Then create an implementation for each environment (ConsoleOutputWriter, TextboxOutputWriter, etc...). Each environment can use the appropriate implementation since they know what type of app they are.

  • 是的,这样的系统已经以TraceListeners的形式存在. (2认同)