0

Possible Duplicate:
How can I conditionally compile my C# for Mono vs. Microsoft .NET?

I'm writing code in C# that uses .NET reflection fairly aggressively, including some features that aren't yet available in Mono. The easy way for me to handle this is with a small number of conditionals:

 #if MONO
        ... stuff that works on mono ....
 #else
        ... stuff that works on .NET 4.0 but not (yet) on mono ...
 #endif

So here's my question: are there any predefined flags I could test this way that either the Mono csharp compiler would have defined automatically, or if not, that the .NET csharp compiler predefines, that I can test this way?

It needs to be a compile-time test (I know how to determine the platform at runtime, but that would be too late)

Community
  • 1
  • 1
Ken Birman
  • 1,088
  • 8
  • 25

1 Answers1

1

Determining the platform at runtime is preferred thing to do. It's not uncommon that program is compiled with Mono's C# compiler and run on .NET (it's even possible to run Mono's C# compiler straight on .NET runtime).

__MonoCS__ is intended for compiler workarounds only and should never be used to limit target platform.

Stewart
  • 4,223
  • 6
  • 31
  • 39
Marek Safar
  • 600
  • 3
  • 8
  • Marek, I definitely agree. As a purist you are quite right. But the issue is that Mono doesn't currently support some of the .NET 4.5 features I use to get exceptions to correctly report the stack after a failure. Sure, I would prefer not to mess with __MonoCS__ but let's face it: if the platforms aren't identical you can run into these issues. – Ken Birman Jun 28 '12 at 20:30
  • By the way, is there a version specific to Mono C# for Android? Turns out that there are additional unsupported options on that platform so I actually need to special case that one too! – Ken Birman Jun 28 '12 at 20:31
  • What .NET 4.5 feature are you missing? Mono will never be identical to .NET and you are not the first one solving this kind of issue but compilation check is definitely not recommended way to do it. – Marek Safar Jun 28 '12 at 21:52