How to tell if there is a console

前端 未结 10 2221
庸人自扰
庸人自扰 2020-12-14 16:34

I\'ve some library code that is used by both console and WPF apps. In the library code, there are some Console.Read() calls. I only want to do those input rea

10条回答
  •  星月不相逢
    2020-12-14 17:08

    You should fix this in your design. This is a nice example of a place in which inversion of control would be very handy. As the calling code is aware of which UI is available, this code should specify an instance of an IInputReader interface, for example. This way, you can use the same code for multiple scenarios for getting input from the user.

提交回复
热议问题