Implementation of some Underscore.js feature in .NET, using C#. If you are a Underscore.js fan and a .NET developer, you will find this library quite interesting.
We will cover Functions part of Underscore.js first. Then we'll move on to other features.
FYI, for Actions with generic type arguments, we have currently limited the number of argument to 4. If required, we will increment it later.
- _.Once(...)
- _.Debounce(...)
- _.Throttle(...)
- _.Negate(...)
First, add the using statement in your file as:
using UnderscoreNet
Then, simply use the methods as you would in Underscore.js.
Example:
using UnderscoreNet;
public class Test
{
public static void DoSomething()
{
Console.WriteLine("Doing something...");
}
public static void Test()
{
var action = Underscore.Once(DoSomething);
action(); // DoSomething gets called here.
action(); // does nothing for this and all subsequent calls
action();
action();
}
}
For somewhat realistic use, please see the example in this blog post.
Please refer to the Underscore.Specs folder for tests with more usage.
using _ = UnderscoreNet.Underscore; // if you know what i mean ;)