views:

98

answers:

1

I have an app that I am developing in Visual Studio 2008, but the projects are set to .NET 2.0. The application will run on a box that only has .NET 2.0 installed.

I understand that I can use some of the features of the .NET 3.5 c# compiler and that it compiles my code to MSIL that .NET 2.0 runtime understands.

What are the features of .NET 3.5 that I can use in my .NET 2.0 app?

Edit: what I have in mind is Extension Methods, Linq, lambdas, object initializers, collection initializers and other compiler candy.

+7  A: 

With no external libraries you can use

  • Lambda expressions
  • Object Initializers
  • Collection Initializers
  • Extension Methods
  • Autoproperties

With the help of an external library like LINQBridge you can also use in memory LINQ queries.

The main feature you cannot use are expression trees because they rely on fixes in the CLR which are not present in a vanilla 2.0 install

JaredPar
You cannot use Extension methods as they need the System.Runtime.CompilerServices.ExtensionAttribute which is located in the System.Core.dll
rstevens
@rstevens, true you need the ExtensionAttribute with the appropriate namespace. But it doesn't have to be in System.Core.dll. It just simply needs to be defined for it to work (and can be defined multiple times). If you define the attribute you can use extension methods in 2.0 (true for both C# and VB.Net)
JaredPar
@JaredPar: If I have the extension method defined in another assembly, does the compiler recognize that method as a valid extension method even if it use a handwritten ExtensionAttribute?
rstevens
@rstevens for an extension method to be defined in another assembly, it must have already bound the ExtensionAttribute in metadata and hence must be available to the referencing assembly in some fashion so yes it can bind the extension method.
JaredPar