Conditional compilation depending on the framework version in C#

前端 未结 5 1361
無奈伤痛
無奈伤痛 2020-11-27 06:08

Are there any preprocessor symbols which allow something like

#if CLR_AT_LEAST_3.5
// use ReaderWriterLockSlim
#else
// use ReaderWriterLock
#endif
         


        
5条回答
  •  再見小時候
    2020-11-27 06:54

    I don't think there are any predefined 'preprocessor' symbols. However you can achieve what you want like this:

    1. Create different configurations of your project, one for every version of CLR you want to support.

    2. Choose a symbol like VERSION2, VERSION3 etc. per CLR version.

    3. In every configuration, define the one symbol associated with it and undefine all others.

    4. Use these symbols in conditional compilation blocks.

提交回复
热议问题