Skip to content

Instantly share code, notes, and snippets.

@jongillies
Created September 22, 2012 22:57
Show Gist options
  • Save jongillies/3768143 to your computer and use it in GitHub Desktop.
Save jongillies/3768143 to your computer and use it in GitHub Desktop.
How to determine your platform in C#
using System;
namespace Supercoder.Tools
{
public class Platform
{
public static string PlatformString()
{
const string msg1 = "This is a Windows operating system.";
const string msg2 = "This is a Unix operating system.";
const string msg3 = "ERROR: This platform identifier is invalid.";
OperatingSystem os = Environment.OSVersion;
PlatformID pid = os.Platform;
switch (pid)
{
case PlatformID.Win32NT:
case PlatformID.Win32S:
case PlatformID.Win32Windows:
case PlatformID.WinCE:
return(msg1);
case PlatformID.Unix:
return(msg2);
default:
return(msg3);
}
}
public static bool IsWindows()
{
OperatingSystem os = Environment.OSVersion;
PlatformID pid = os.Platform;
switch (pid)
{
case PlatformID.Win32NT:
case PlatformID.Win32S:
case PlatformID.Win32Windows:
case PlatformID.WinCE:
return (true);
default:
return (false);
}
}
public static bool IsUnix()
{
OperatingSystem os = Environment.OSVersion;
PlatformID pid = os.Platform;
switch (pid)
{
case PlatformID.Unix:
return (true);
default:
return (false);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment