C# 3 and LINQ on .net 2 6
My friend Patrick is wondering what’s the best way to use the type System.Collections.Generic.HashSet, in NDepend, that he wants to deploy on computers with only .net 2 installed.
Well it’s pretty simple, the best way to get it, is to get it from Mono. The code is licensed under the MIT/X11 license, allowing multiple usages.
And that’s not all. If you’re dying to use C#3 or LINQ to objects in your application, but that you want to be able to release on .net 2 only, you can simply compile and ship Mono’s implementation of System.Core. Microsoft’s C# compiler, csc 3.5, won’t have any issue using it, et voilĂ , you’ll get an application using LINQ or C#3, and deployable on .net 2.
Mono’s implementation of System.Core is available in SVN here.
Trackbacks
Use the following link to trackback from your own site:
http://evain.net/blog/articles/trackback/508

It sounds so easy. It sounds so useful. Everybody would like to do this. I wouldn’t have a clue how to get my C#2 modules working with the 3.0 ‘Core’ from mono.
Could someone show us how, or maybe, could mono releases just ship the compatibility assemblies if it’s so easy to make them?
Regards
If you don’t feel like checking the sources out from svn and compiling it yourself, you can install a release candidate of Mono 2.0, and pick the binary there.
I recently tried to borrow the System.Core.dll from mono 1.9.1, but I had problems using it on windows due to strong naming.
Because I only needed a small subset of the common Linq features, and the Func/Action types, I created my own implementations in a new namespace, and used gmcs -noconfig option to remove the default dependency on System.Core.dll.
This might have been an overly complicated way to get the job done, but it works just fine in ms.net 2.0 and 3.5.
I strongly encourage you to get System.Core from either Mono’s trunk, or from the 2.0 branch (or release candidate), it’s much more robust than what you’ll find on 1.9.1.
Mono HashSet.cs does not compile under Net 2.0 because it uses the var keyword. As I needed a Set-Implementation, I did a “backport” to Net 2.0 without var-usage. You can download it here: http://downloads.sourceforge.net/limad/Limaki.Graphics0.064.zip
The adopted HashSet.cs is in:
Common\Collections\MonoHashSet.cs
Mono’s System.Core won’t compile on .net 2, but you cam compile it on a .net 3.5 machine, and ship it on .net without any issue.