views:

64

answers:

2

Suppose I have a LINQ method that I wanted to run using normal LINQ if the Net Framework 3.5 is installed, but using PLINQ if 4.0 or higher is installed. Is this possible ?

+2  A: 

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 #if directives.
Mark Byers
A: 

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.

tdyen
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 ?
miket2e