Created
September 22, 2012 22:57
-
-
Save jongillies/3768143 to your computer and use it in GitHub Desktop.
How to determine your platform in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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