C#编译单 - 检测OS [英] C# compiled in mono - Detect OS
本文介绍了C#编译单 - 检测OS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获得OSX下运行的C#应用程序,它是不完全无痛。要解决的一些问题在短期内,我想到的是,当它在运行OSX设立一些具体的规则。
I am trying to get a C# app running under OSX which is not exactly pain free. To work around some of the issues in the short term, I am thinking of setting up some specific rules when it is running in OSX.
但是...我可以用它来确定应用程序是否在Windows或OSX下运行?
But... What can I use to determine whether the app is running under Windows or OSX?
推荐答案
从单声道维基(以我的经验,OSX标识为Unix的):
From the Mono wiki (in my experience, OSX is identified as Unix):
int p = (int) Environment.OSVersion.Platform;
if ((p == 4) || (p == 128)) {
Console.WriteLine ("Running on Unix");
} else {
Console.WriteLine ("NOT running on Unix");
}
或
string msg1 = "This is a Windows operating system.";
string msg2 = "This is a Unix operating system.";
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:
Console.WriteLine(msg1);
break;
case PlatformID.Unix:
Console.WriteLine(msg2);
break;
default:
Console.WriteLine(msg3);
break;
}
}
这篇关于C#编译单 - 检测OS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文