Documentation - JasonBock/SpackleNet GitHub Wiki
Spackle is a project that contains a number of helper methods I've used to supplement the core classes in .NET. Following is a brief list of code examples that illustrate what you can do with Spackle. Note that this list all-inclusive - you're encouraged to look through the unit tests to see what else Spackle has.
You can perform rotations, shuffling, and element swapping with IList<T>-based objects:
var items = new List<string> { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" };
items.Rotate(7, RotateDirection.Negative);
// items is now { "h", "i", "j", "a", "b", "c", "d", "e", "f", "g" }
items.Swap(2, 4);
// items is now { "h", "i", "b", "a", "j", "c", "d", "e", "f", "g" }
items.Shuffle();
// items are now in a different order (hopefully!),
// something like { "c", "a", "b", "g", "d", "f", "e", "i", "j", "h" }
You can also create a read-only collection from an enumeration:
var collection = new HashSet<string> { "A", "B", "A" }.AsReadOnly();
This is a powerful way to change the value of a property, field, or local variable in a scope (via the use of the using keyword):
using(Cursors.Wait.Bind(() => someWindow.Cursor))
{
// Within this block, someWindow.Cursor will be set to Cursors.Wait.
// Upon exiting the block, someWindow.Cursor will be set back to its original value.
}
If you've ever wanted to do a quick performance test on a piece of code, look no further than the Time() extension method:
Console.Out.WriteLine(new Action<int, int, int>(
(arg1, arg2, arg3) =>
{
var x = arg1 + arg2 + arg3;
}).Time(0, 0, 0).TotalMilliseconds);
If you want to do real performance testing, I highly encourage you to use Benchmark.NET.
Ever want to change a string to a Uri?
"http://www.goodsite.com".AsUri();
Spackle defines a generic Range class to define and intersect other ranges:
var range = new Range<int>(3, 10);
var isInRange = range.Contains(5); // isInRange is true
var newRange = range.Intersect(new Range<int>(5, 12)); // newRange is (5, 10)
In C# 8, the Range type was introduced. Support was added in Spackle for this type for intersections and unions as well as partitioning a range. Look at the partitioning tests to see how it works.
The SecureRandom class combines the simplicity of the Random class with the security of the RandomNumberGenerator.
The latest release of Spackle is available through NuGet. You can also clone the repo it via the GitHub site.