C# compiled in mono - Detect OS(以单声道编译的 C# - 检测操作系统)
问题描述
我正在尝试让 C# 应用程序在 OSX 下运行,这并不是完全没有痛苦的.为了在短期内解决一些问题,我正在考虑在 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?
推荐答案
来自 Mono wiki(根据我的经验,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# - 检测操作系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!