Giter Site home page Giter Site logo

kouweizhong / netlegacysupport Goto Github PK

View Code? Open in Web Editor NEW

This project forked from saladlab/netlegacysupport

0.0 1.0 0.0 2.63 MB

Library helps supporting old .NET frameworks like .NET 2.0 and 3.5.

License: MIT License

Batchfile 0.26% F# 0.80% C# 98.94%
concurrent

netlegacysupport's Introduction

NetLegacySupport

Build status Coverage Status

Library helps supporting old .NET frameworks like .NET 2.0 and 3.5. This is a backport from .NET Core. Following classes are provided:

  • System.Action
  • System.Tuple
  • System.Collections.Concurrent.ConcurrentDictionary

System.Action

Action and Func is quite tricky to use in a multi target framework project because 2.0, 3.0 and 3.5 framework just provided subset of them.

  • .NET Framework 2.0, 3.0 supports only Action<T>
  • .NET Framework 3.5 supports Action, Func has up to 4 parameters.
  • .NET Framework 4.0 supports Action, Func has up to 16 parameters.

To deal with this problem, this library provides missing classes in target framework.

Where can I get it?

PM> Install-Package NetLegacySupport.Action

Code that you can write.

Func<int, int, int, int, long> f =
    (a, b, c, d) => { return (long)a + b + c + d; };
Console.WriteLine(f(1, 2, 3, 4)); // 10

System.Tuple

Until .NET Framework 4, tuple was not supported. But it's an essential class that makes your code terse.

Where can I get it?

PM> Install-Package NetLegacySupport.Tuple

Code that you can write.

Tuple<int, string> t = Tuple.Create(1, "One");
Console.WriteLine(t); // (1, "One")

ConcurrentDictionary

ConcurrentDictionary is quite useful dictionary with a thread-safe feature. If your project is targeted toward .NET 3.5 only, Task Parallel Library for .NET 3.5 can be an option.

Where can I get it?

PM> Install-Package NetLegacySupport.ConcurrentDictionary

Code that you can write.

// New instance. (from http://www.dotnetperls.com/concurrentdictionary)
var con = new ConcurrentDictionary<string, int>();
con.TryAdd("cat", 1);
con.TryAdd("dog", 2);

// Try to update if value is 4 (this fails).
con.TryUpdate("cat", 200, 4);

// Try to update if value is 1 (this works).
con.TryUpdate("cat", 100, 1);

// Write new value.
Console.WriteLine(con["cat"]);

netlegacysupport's People

Contributors

veblush avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.