Posts Tagged ‘PlatformID’

Mono PlatformID on MacOS X

Unfortunately, the method mentioned in the Mono Technical FAQ, where you can check System.Environment.OSVersion.Platform for a value of 6 doesn’t work (as of Mono 2.6). I got the following code from this thread, which works well enough,

[DllImport("libc")]
static extern int uname(IntPtr buf);

static bool IsRunningOnMac()
{
IntPtr buf = IntPtr.Zero;
try
{
buf =
Marshal.AllocHGlobal(8192);
if (uname(buf) == 0)
{
string os = Marshal.PtrToStringAnsi(buf);
if (os == "Darwin") return true;
}
}
catch { }
finally
{
if (buf != IntPtr.Zero) Marshal.FreeHGlobal(buf);
}
return false;
}