Search code examples
c#uwpconsole-applicationdesktop-application

Determine if library loaded into Console, Desktop, or UWP app


I have a libary which needs to behave differently for console applications, desktop application (e.g. WPF), and for UWP apps.

How can I determine at run-time into which application type my libary is loaded?

Determining if it is a console application seems easy: How to tell if there is a console

For UWP, I can probably determine if WinRT is loaded. But how?

What distinguishing attributes do desktop applications have?


Solution

  • I ended up defining following enum:

    public enum ExecutionMode
    {
        Console,
        Desktop,
        UniversalWindowsPlatform
    }
    

    which is passed to the constructor of the main class of my libary. Not a new idea, but very reliable (if used correctly).