Invest in people before investing in tools

Il blog di Matteo Baglini
posts - 118, comments - 95, trackbacks - 697

Usare LINQ to Objects in progetti .NET 2.0/3.0

Come fare ad usare LINQ to Objects, quindi .NET 3.5, se lavorate su un progetto .NET 2.0/3.0 con Visual Studio 2008 (grazie alle funzionalità di multi-targeting) ?? Semplice, basta reimplementare tutti i query operators smile_wink. Oppure utilizzare la libreria LINQBridge scritta da Joseph Albahari:

With Studio's multi-targeting and LINQBridge, you'll be able to write local (LINQ to Objects) queries using the full power of the C# 3.0 compiler—and yet your programs will require only Framework 2.0.

LINQBridge is a reimplementation of all the standard query operators in Framework 3.5's Enumerable class. It's designed to work with the C# 3.0 compiler, as used by Visual Studio 2008. LINQBridge comprises a "LINQ to Objects" API for running local queries. (It doesn't include an implementation of LINQ to SQL, nor LINQ to XML; a good compromise can be to force Framework 3.5 out to just the server machines, allowing LINQ to SQL to be used where it's needed most).

LINQBridge also includes Framework 3.5's generic Func and Action delegates, as well as ExtensionAttribute, allowing you to use C# 3.0's extension methods in Framework 2.0.

In fact LINQBridge lets you use nearly all of the features in C# 3.0 with Framework 2.0—including extension methods, lambda functions and query comprehensions. The only feature it does not support is compiling lambdas to expression trees (i.e., Expression<TDelegate>).

Technorati Tag: ,

Print | posted on venerdì 29 febbraio 2008 23:07 | Filed Under [ .NET ]

Powered by:
Powered By Subtext Powered By ASP.NET