可能重复:
How to detect which .NET runtime is being used (MS vs. Mono)?
在.net中我如何判断我的代码是否在Mono上运行?
答案 0 :(得分:18)
来自Mono FAQ:
http://www.mono-project.com/FAQ:_Technical
以下是该链接:
如何检测我是否在Mono中运行?
具有依赖于底层运行时的代码被认为是 糟糕的编码风格,但有时这样的代码是必要的解决方案 运行时错误。检测Mono的支持方式是:
using System;
class Program {
static void Main ()
{
Type t = Type.GetType ("Mono.Runtime");
if (t != null)
Console.WriteLine ("You are running with the Mono VM");
else
Console.WriteLine ("You are running something else");
}
}
任何其他hack,例如检查System.Int32的基础类型 或其他corlib类型,将来注定要失败。
长短不一,只是不要。
答案 1 :(得分:11)
public static bool IsRunningOnMono ()
{
return Type.GetType ("Mono.Runtime") != null;
}