What is the alternative to having code with conditional compilation in C#?
I have a class that has lots of code that is based on # ifdef .. After sometime my code is unr
Expanding on Jon's answer, while there a number of limitations on using the ConditionalAttribute
, there is a significant advantage. When the condition is false, the calls to conditional method are omitted. For example, you can add 100's of calls to a logging system, say for debugging, that can be conditionally excluded from the production code. When they are excluded, there is no overhead associated with calling a method which does not need to be called. Using #ifdef, you would have to wrap every call to the logging system to conditionally exclude them.
Note this only works across assemblies, if the caller of the conditional method is re-compiled.