I'm retrieving the operating system platform with .NET Core with system.runtime.interopservices
I 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.
/// <summary>
/// Operating System Class
/// For Retrieving The OS
/// Platform.
/// AE : 9/08/2018
/// </summary>
class OperatingSystem
{
/// <summary>
/// Operating System Platforms.
/// </summary>
public enum OSPlatform
{
Windows,
OSX,
Linux,
Not_Supported
}
/// <summary>
/// Return Operating System
/// </summary>
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();
}
switch
es? I find it's a bad idea to duplicate those values without a very good reason. \$\endgroup\$