Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Several custom configuration in #if directive

I need the following logic

#if (DEV || QA || RELEASE)
//add when dev or qa or release configuration
#endif

Is it possible in c#?

like image 824
Pavel Avatar asked Sep 16 '25 11:09

Pavel


2 Answers

Yes. Quoting the #if documentation on MSDN:

You can use the operators && (and), || (or), and ! (not) to evaluate whether multiple symbols have been defined. You can also group symbols and operators with parentheses.

like image 153
clcto Avatar answered Sep 19 '25 01:09

clcto


#define DEBUG 
#define MYTEST
using System;
public class MyClass 
{
    static void Main() 
    {
#if (DEBUG && !MYTEST)
        Console.WriteLine("DEBUG is defined");
#elif (!DEBUG && MYTEST)
        Console.WriteLine("MYTEST is defined");
#elif (DEBUG && MYTEST)
        Console.WriteLine("DEBUG and MYTEST are defined");
#else
        Console.WriteLine("DEBUG and MYTEST are not defined");
#endif
    }
}

Here simple code how to do it. You can read full documentation on C# Preprocessor Directives

like image 44
mybirthname Avatar answered Sep 19 '25 00:09

mybirthname