I need a conditional compilation switch that knows if I am compiling for the mono or MS .NET runtime. How can I do this?
Conditional compilation is the process of selecting which code to compile and which code to not compile similar to the #if / #else / #endif in C and C++. Any statement that is not compiled in still must be syntactically correct. Conditional compilation involves condition checks that are evaluable at compile time.
Conditional compilation provides a way of including or omitting selected lines of source code depending on the values of literals specified by the DEFINE directive. In this way, you can create multiple variants of the same program without the need to maintain separate source streams.
The #define creates a macro, which is the association of an identifier or parameterized identifier with a token string. After the macro is defined, the compiler can substitute the token string for each occurrence of the identifier in the source file.
The Mono compiler defines __MonoCS__
BUT, BUT, BUT, the whole point of Mono is that you can take an assembly that you built with VS and run it on Mono, or vice versa.
It seems to me that if you need to have Mono vs MS.NET differences, then you need to be making those decisions at run-time.
The standard way to detect Mono at Runtime is:
bool runningOnMono = Type.GetType ("Mono.Runtime") != null;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With