I’ve added the first reader Q & A item to the Effective C# book blog:
In the section on Conditionals you say that in order to create a method that will fire if more than one condition is true (logical AND), you need to use
#if (VAR1 && VAR2)
However, it is possible to chain the conditionals together (according to MSDN, anyway…)
[Conditional("A")] public static void IfAandB( )
[Conditional("B")] static void AandBPrivate( )
/* Code to execute when both A and B are defined... */
Call IfAandB; if both A and B are defined, AandBPrivate will execute.
Is there any reason to use your method above the MS one?
You can read the full answer here:
All of these projects are Open Source (using the Creative Commons license for content, and the MIT license for code). If you would like to contribute, visit our GitHub Repository. Or, if you have questions, comments, or ideas for improvement, please create an issue for us.