以单声道编译的 C# - 检测操作系统

C# compiled in mono - Detect OS(以单声道编译的 C# - 检测操作系统)
本文介绍了以单声道编译的 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# - 检测操作系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)