“Compatibility Pack” for backporting new .NET Framework features?

走远了吗. 提交于 2019-11-30 11:35:33
Theraot

Theraot's Libraries

You can use use Theraot.Core from Theraot's Libraries to backport a great portion of .NET code to old versions starting with .NET 2.0 thanks to conditional compilation.

Out of the mentioned features, the following are included:

  • ExtensionAttribute
  • Func<...> and Action<...> delegates
  • LINQ-to-objects
  • Tuple<...>
  • Lazy<T> and Lazy<T,TMetadata>
  • Expression Tress

Also included are the following features not mentioned in the question:

  • HashSet<T>
  • SortedSet<T>
  • ThreadLocal<T>
  • IObservable<T> and IObserver<T>
  • BigInteger
  • ConcurrentDictionary<Tkey, TValue>
  • etc...

Note: Support for System.Threading.Tasks is planned.

Sadly, there is only little documentation available at the moment of writing, yet any difference on behavior from the BCL can be considered a bug, and can be reported via github.

Lucas

This isn't really a "compatilibity pack", but since you mentioned LinqBridge... another "backported feature" I frequently use are the Parallel Extensions found (among other things) in the Reactive Extensions (Rx) for Framework 3.5 SP1 (in System.Threading.dll). It includes full implementation of the Task Parallel Library and Parallel LINQ (PLINQ).

For .Net 4.0 there is the Async Targeting Pack for Visual Studio 2012 (nuget) from Microsoft. Which provides many Async extention methods and provides support for the async/await keywords if using the C# 5 compiler.

Similarly for for .Net 3.5 there is the AsyncBridge that builds on the Reactive Extentions's TPL library to provide async/await. There is also a version of AsyncBridge for .Net 4.0, but I am not sure why you would want that one over the one from Microsoft.

johv

For .NET 3.5 you can use FSharp.Core.dll from the F# Runtime for .NET Framework 2.0.

"The core library (FSharp.Core.dll) included in this redistributable package contains some APIs in the System namespaces that are identical to .NET Framework 4 APIs that are required for F# development."

http://msdn.microsoft.com/en-us/library/ee829875%28v=vs.100%29.aspx

This includes System.Tuple et al. and System.Lazy<T>. (Not Lazy<T,TMetadata> though.) To use them just reference FSharp.Core.dll.

Edit: Turns out Lazy in FSharp.Core.dll is not a drop-in replacement, but more of an interop-class. It has the same properties but not the same constructors. Rather it's created e.g. like this:

Lazy<string> lazy = Microsoft.FSharp.Control.LazyExtensions.CreateFromValue("test");

I don't know how useful such a list will be, as it is potentially monstrous in size. The CLR is the same for 2.0, 3.0 & 3.5 so tehnically any of these post-2.0 features could make their way into a "compatibilty pack."

-Oisin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!