是否有可能有条件地编译到.NET Framework版本? [英] Is it possible to conditionally compile to .NET Framework version?

查看:159
本文介绍了是否有可能有条件地编译到.NET Framework版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还记得回来MFC工作时,你可以支持多个版本的MFC框架通过检查 _MFC_VER 宏。

我做的一些东西现在随着.NET 4中,并想用元组在几个点,但仍保留一切3.5兼容。

我希望做这样的事情:

 #如果DOTNET4
    公开元组LT; TSource,TResult>的someMethod&所述; TSource,TResult>(){...}
#其他
    公共KeyValuePair< TSource,TResult>的someMethod&所述; TSource,TResult>(){...}
#ENDIF
 

解决方案

有可以不使用内置precompiler常数。但是,这是很容易的创建VS自己的编译配置,每种配置有它自己的一套定义的常量,当然还有一个目标框架的版本。很多人这样做是为了有条件地编译基于32位或64位的差异。

I can recall back when working with MFC you could support multiple versions of the MFC framework by checking the _MFC_VER macro.

I'm doing some stuff now with .NET 4 and would like to use Tuple in a couple of spots but still keep everything else 3.5 compatible.

I'm looking to do something like:

#if DOTNET4
    public Tuple<TSource, TResult> SomeMethod<TSource, TResult>(){...}
#else
    public KeyValuePair<TSource, TResult> SomeMethod<TSource, TResult>(){...}
#endif

解决方案

There are no builtin precompiler constants that you can use. But, it is easy enough create your own build configurations in VS with each configuration having its own set of defined constants and of course a target framework version. A lot of people do this to conditionally compile based 32 or 64 bit differences.

这篇关于是否有可能有条件地编译到.NET Framework版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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