Search code examples
monodeveloppreprocessor-directive

Monodevelop marks everything between #if and #endif as a comment in C# file


I'm using the version of MonoDevelop bundled with Unity game engine. I never used #if/#endif in C# before, so I never noticed that. I checked this on a new empty file. How can I fix that?


Solution

  • I've played around with this a bit and what I've noticed is that conditional code for a "#if DEBUG" block is commented out. It's probably helpful when you've gotten to the point of building your release code. The "debug" test stuff remains in your code, but looks like a comment. Here is what I was playing with to test that out, ymmv:

    using System;
    namespace testConditionalCompile
    {
       class MainClass
       {
          public static void Main (string[] args)
          {
    
    #if RELEASE         
              Console.WriteLine("Release code"); 
    #endif          
    
    #if DEBUG   
              Console.WriteLine("Debug code");          
    #endif
            }
        }
    }
    

    I realize that the conditional code block is not the best way to write it, but I thought it might best illustrate my point above.