Are there any preprocessor symbols which allow something like
#if CLR_AT_LEAST_3.5 // use ReaderWriterLockSlim #else // use ReaderWriterLock #endif
or some other way to do this?
The compiler directives that are used for conditional compilation are the DEFINE directive, the EVALUATE directive, and the IF directive.
The preprocessor conditional compilation directive spans several lines: The condition specification line (beginning with #if , #ifdef , or #ifndef ) Lines containing code that the preprocessor passes on to the compiler if the condition evaluates to a nonzero value (optional) The #elif line (optional)
These are for compiler constants, for example: #if DEBUG Debug.WriteLine("This is written in debug mode"); #endif. If the DEBUG constant is defined, that code gets compiled, if it's not then it's stripped out, ignored by the compiler..it's a way to determine what's in a certain build type, and stripped out for another.
I don't think there are any predefined 'preprocessor' symbols. However you can achieve what you want like this:
Create different configurations of your project, one for every version of CLR you want to support.
Choose a symbol like VERSION2
, VERSION3
etc. per CLR version.
In every configuration, define the one symbol associated with it and undefine all others.
Use these symbols in conditional compilation blocks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With