Note that there are some explanatory texts on larger screens.

plurals
  1. PO"Compatibility Pack" for backporting new .NET Framework features?
    text
    copied!<p>For various reasons I often find it desirable to write code that is compatible with .NET framework 2.0 or 3.5 or compatible with the .NET Compact Framework, but it is a problem that there are numerous "small" features in new .NET frameworks that are not available in the older frameworks or Compact Framework.</p> <p>For example, I find extension methods are really useful, but the compiler depends on <code>System.Runtime.CompilerServices.ExtensionAttribute</code> for this. You can easily define this attribute yourself and then use extension methods in .NET Framework 2.0 (under C# 3.0+). Likewise, it isn't too hard to manually define little .NET 4 types like <code>Tuple&lt;T1,T2&gt;</code> and <code>Lazy&lt;T&gt;</code>. By the way, if you want to use LINQ in .NET 2.0, you can use <a href="http://www.albahari.com/nutshell/linqbridge.aspx" rel="noreferrer">LinqBridge</a>.</p> <p>Now suppose you make the <code>ExtensionAttribute</code> public so that other assemblies you write can use it. That's fine at first, but what if you then want to use a 3rd party library that also had the same idea? You add a reference to that library and now you've got a name collision. Oops.</p> <p>I have also noticed that some new libraries are only available for .NET 4.0 or 3.5 even though they only have minor dependencies on it that could be resolved using a compatibility pack or LinqBridge.</p> <p>It would sure be nice if there were "compatibility packs" for older .NET versions that defined these little features in a small DLL that you could justify including in projects of any size. Does such a thing exist?</p> <p><strong>Update</strong>: Judging by the silence, I guess there's no such thing. I might make such a OSS library myself if there is interest. So my new question is, what <em>smaller</em> features of .NET 4 (as opposed to monsters like WCF/WPF) would you miss if you were writing for .NET 2, .NET 3.5, .NETCF or Silverlight? I'll start the list off...</p> <ul> <li><code>ExtensionAttribute</code> (not in .NET 2)</li> <li><code>Func&lt;...&gt;</code> and <code>Action&lt;...&gt;</code> delegates (not in .NET 2)</li> <li>LINQ-to-objects (not in .NET 2)</li> <li><code>Tuple&lt;...&gt;</code> (not in .NET 3.5)</li> <li><code>Lazy&lt;T&gt;</code> and <code>Lazy&lt;T,TMetadata&gt;</code> (not in .NET 3.5)</li> <li>Expression Trees (not in .NET 2; incomplete in .NET 3.5)</li> <li>Generics Variance (exists in .NET 2 but inaccessible from C# 3 and VB 9)</li> <li><code>Reflection.Emit</code> (missing from .NETCF; not really a small feature but I miss it very much)</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload