Ive 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 reads if the app is a console app not if its a GUI app - how to tell in dll if the app has a console?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
if you want a good design, abstract the GUI dependences using an interface. Implements a concrete class for the console version, another for the WPF version, and inject the correct version using any way (dependency injection, inversion of control, etc).
I rewrote @Ricibob's answer
It is simpler, but I prefer this native implementation:
In the end I did as follows:
Following thekips advice I added a delegate member to library class to get user validation - and set this to a default implimentation that uses above to check if theres a console and if present uses that to get user validation or does nothing if not (action goes ahead without user validation). This means:
Thanks to all who replied.
You can pass argument on initialize.
for example:
In your library class, add constructor with 'IsConsole' parameter.
And from Console you can use:
Form wpf: