Is it possible to run a LINQ method using normal LINQ if the Net Framework 3.5 is installed, but using PLINQ instead if 4.0 or higher is installed ?
-
4I think it is unwise to implement 2 pieces of code that perform the same task unless there is a really big advantage. This would double the probability of bugs, and potentially lead to inconsistent behavior that is twice as hard to track down.mikerobi– mikerobi2010-10-31 00:11:49 +00:00Commented Oct 31, 2010 at 0:11
-
I agree, I don't think this would be good practice in general. The alternatives - always code for the 'lowest common denominator' framework, or force your clients to upgrade - aren't that attractive either though. I was just wondering if there was an additional option, kind of like how web designers can code their sites to look great in newer browsers and degrade gracefully in older ones.Michael Low– Michael Low2010-10-31 10:38:37 +00:00Commented Oct 31, 2010 at 10:38
Add a comment
|
2 Answers
I don't think that's possible. Here are some alternatives:
- If it is at all an option it would be much simpler to require your users to upgrade to .NET 4.0.
- If you can't require your users to upgrade you can spend a little more time improving the .NET 3.5 code so that you don't need to make a special .NET 4.0 version.
- Or you can make two different builds of your project using
#ifdirectives.
Comments
While i also don't think its wise to code two versions you can use the Environment.Version variable.
It is there in all .net versions since 1.1 and Silverlight.
1 Comment
Michael Low
I'm aware of Environment.Version, but I can't see it would work here. To get the optional PLINQ code to compile I'd have to set Target Framework to 4.0, and in that case it wouldn't run on machines without the 4.0 Framework installed. If you disagree, can you post example code ?