Or an operator in a conditional attribute in C #

In C #, we can differentiate code execution depending on the type of assembly. By default, we defined the types Debug and Release.
We can do this using the #if directive:

 #if DEBUG public void Foo() { ... } #endif 

But we can also use the Conditional attribute:

 [Conditional("DEBUG")] public void Foo() { ... } 

The second solution is claimed to be more serviceable (see: Effective C # by Bill Wagner).

My question is: how can I use the Conditional attribute with many build configurations? Is there any way to use the or operator? I ask, because I want some Foo method to be executed as, for example, in the DEBUG and BAR assembly configurations. What then?

+45
c #
Dec 02 '15 at 8:43
source share
1 answer

You can use several conditional attributes separated by commas, for example

 [Conditional("DEBUG"), Conditional("BAR")] 

and this will be exactly your desired behavior - they will be logically combined together.

See MSDN for help.

+50
Dec 02 '15 at 8:46
source share



All Articles