Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 885
William Jockusch Avatar asked Dec 01 '13 23:12

William Jockusch


2 Answers

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

like image 62
Erik Kerber Avatar answered Sep 23 '22 10:09

Erik Kerber


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.

like image 41
KnechtRootrecht Avatar answered Sep 19 '22 10:09

KnechtRootrecht