Retrieving OS Platform .NET Core I'm retrieving the operating system platform with .NET Core with system.runtime.interopservicesI have created the code below and was wondering if there was any other way that I could improve it since I haven't been able to get a switch statement to work in the OperatingSystem class.

/// &lt;summary&gt;
/// Operating System Class
/// For Retrieving The OS
/// Platform.
/// AE : 9/08/2018
/// &lt;/summary&gt;
class OperatingSystem
{
    /// &lt;summary&gt;
    /// Operating System Platforms.
    /// &lt;/summary&gt;
    public enum OSPlatform
    {
        Windows,
        OSX,
        Linux,
        Not_Supported
    }

    /// &lt;summary&gt;
    /// Return Operating System
    /// &lt;/summary&gt;
    public static OSPlatform GetPlatform
    {
        // Switch Statement Not Compatitable
        get
        {
            if (RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
            {
                return OSPlatform.Windows;
            }
            else if (RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX))
            {
                return OSPlatform.OSX;
            }
            else if (RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux))
            {
                return OSPlatform.Linux;
            }
            else
            {
                return OSPlatform.Not_Supported;
            }
        }
    }
}


The class is being called like this,

static void Main()
{
    switch (OperatingSystem.GetPlatform)
    {
        case OperatingSystem.OSPlatform.Windows:
            Console.WriteLine("Goto Windows Class");
            break;
        case OperatingSystem.OSPlatform.OSX:
            Console.WriteLine("Goto OSX Class");
            break;
        case OperatingSystem.OSPlatform.Linux:
            Console.WriteLine("Goto Linux Class");
            break;
        default:
            Console.WriteLine("OS Not Supported");
            break;
        }
        Console.ReadKey();
    }
Review


Don't use underscores in enum values NotSupported
The enum value with integer value 0 represents its default value; I would make this NotSupported in order to avoid some bias
GetPlatform is a method name; prefer Platform as property name
Since the platform won't change while your program is running, consider using a Lazy to retrieve the platform once.


Don't like if-statements?

Let's first refactor the enum to match aforementioned conventions:

public enum OSPlatform
{
    NotSupported,
    Windows,
    OSX,
    Linux,
}


We could then use a Lazy:

 static readonly Lazy&lt;OSPlatform&gt; platform = new Lazy&lt;OSPlatform&gt;(GetPlatform, true);
 public static OSPlatform Platform =&gt; platform.Value;


And refactor the intitial method using a helper generator using a simple ValueTuple to avoid the boiler-plate if-statements. 

private static IEnumerable
    &lt;(OSPlatform Platform, RuntimeOSPlatform RuntimePlatform)?&gt; EnumeratePlatforms() 
{
    yield return (OSPlatform.Windows, RuntimeOSPlatform.Windows);
    yield return (OSPlatform.OSX, RuntimeOSPlatform.OSX);
    yield return (OSPlatform.Linux, RuntimeOSPlatform.Linux);
}

private static OSPlatform GetPlatform()
{
    return EnumeratePlatforms().FirstOrDefault(p 
       =&gt; RuntimeInformation.IsOSPlatform(p.Value.RuntimePlatform))?.Platform ?? default;
}


I've created an alias to avoid redundant namespace code:

using RuntimeOSPlatform = System.Runtime.InteropServices.OSPlatform;


If you want to have some fun, you could refactor this solution to use Expression and some reflection to avoid creating hard-coded tuples.