Destructuring extension methods for awesome C#
In C# 7.0:
using DestructureExtensions;
/*...*/
var stringToSplit = "foo,bar,bam,baz";
var (first, _, third, rest) = stringToSplit.Split(',');
// first == "foo"
// third == "bam"
// rest == IEnumerable<string> containing "baz"
var one = Task.FromResult(1);
var two = Task.FromResult("foo");
var three = Task.FromResult(DateTimeOffset.Now);
var (first, second, third) = await (one, two, three).WhenAll();
var tasks = Enumerable.Range(1, 10).Select(Task.FromResult);
var results = await tasks.WhenAll();
var dictionary = new Dictionary<string, int>()
{
{ "one", 1 },
{ "two", 2 },
{ "three", 3 },
}
foreach (var (key, value) in dictionary)
{
// ...
}
More examples in the unit tests.
Ensure you have installed .NET Core
To build a local/development NuGet package, run the following:
dotnet restore
dotnet build
dotnet pack
This will produce bin/Debug/DestructureExtensions.0.0.0.nupkg
.
We are committed to fostering an open and welcoming environment. Please read our code of conduct before participating in or contributing to this project.
We welcome contributions and collaboration on this project. Please read our contributor's guide to understand how best to work with us.
This software is made available by Daniel James under the MIT license.