Does Xamarin have an #if or #ifdef for determining the platform?

久未见 提交于 2019-12-10 03:14:37

问题


For example, #ifdef iOS, #ifdef android, or the like. If there is #if, that would be even better.


回答1:


iOS:

#if __MOBILE__
    Console.WriteLine ("__MOBILE__ is defined");
#endif 

#if __IOS__
    Console.WriteLine ("__IOS__ is defined");
#endif 

Android:

#if __MOBILE__
    Console.WriteLine ("__MOBILE__ is defined");
#endif 

#if __ANDROID__
    Console.WriteLine ("__ANDROID__ is defined");
#endif

https://bugzilla.xamarin.com/show_bug.cgi?id=6459#c12

xamarin documentation




回答2:


Yes it does, I don't know, if Xamarin.iOS provides its own symbols, as I'm new to Xamarin and I actually do not use Xamarin.iOS, but you can define your own symbols.

Right click on the project an open the project options. In the "Compiler" settings you can lookup existing flags and create add new ones. For example here are the symbols that are shipped with Xamarin.Android:

DEBUG;__MOBILE__;__ANDROID__;

The flags should be available immediately after you have defined them.



来源:https://stackoverflow.com/questions/20318410/does-xamarin-have-an-if-or-ifdef-for-determining-the-platform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!