Pavel
Pavel

Reputation: 1127

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#?

Upvotes: 4

Views: 1863

Answers (3)

mybirthname
mybirthname

Reputation: 18127

#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

Upvotes: 2

clcto
clcto

Reputation: 9648

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.

Upvotes: 9

Related Questions