这取决于在C#中的框架版本条件编译 [英] Conditional compilation depending on the framework version in C#

查看:112
本文介绍了这取决于在C#中的框架版本条件编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有允许像

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

或一些其他的方式做到这一点?

or some other way to do this?

推荐答案

我不认为有pdefined'preprocessor'符号的任何$ P $。然而,你可以达到你想要的东西是这样的:

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


  1. 创建项目,一个CLR的每一个版本要支持的不同配置。

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

选择像 VERSION2 版本3 符号等每CLR版本。

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.

这篇关于这取决于在C#中的框架版本条件编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆