2010-12-10 21 views

回答

14

那麼你當然可以使用

#if MONO 

,然後用

gmcs -define:MONO ... 

編譯(或者把你的單聲道構建配置,當然,這要看你如何建立你的圖書館)。

...你在尋找什麼?

19

優選的方法是使用運行時的檢測,因爲這允許爲任何平臺上使用的同樣的組件:

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"); 
    } 
} 
+0

並不能幫助我們這些想使用單特異性功能... – 2013-06-26 16:43:15

41

雖然運行時檢查可能是優選的,與所述單聲道編譯器,所述預定義的__MonoCS__常數是有用的,例如

#if __MonoCS__ 
// Code for Mono C# compiler. 
#else 
// Code for Microsoft C# compiler. 
#endif 
+1

只要確保沒有開發人員添加了誰__ __ MonoCS到Visual Studio項目建設的屬性,然後想知道爲什麼編譯代碼不能按預期工作! : -/ – Stewart 2012-09-10 13:08:29