Skip to content

Destructuring extension methods for awesome C#

License

Notifications You must be signed in to change notification settings

thzinc/DestructureExtensions

Folders and files

NameName
Last commit message
Last commit date
Jan 31, 2019
Feb 9, 2019
Feb 9, 2019
Sep 28, 2017
Jan 31, 2019
Oct 8, 2017
Oct 8, 2017
Jan 31, 2019
Oct 8, 2017
Jan 31, 2019
Feb 9, 2019

Repository files navigation

DestructureExtensions

Destructuring extension methods for awesome C#

Quickstart

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.

Building

Travis NuGet

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.

Code of Conduct

We are committed to fostering an open and welcoming environment. Please read our code of conduct before participating in or contributing to this project.

Contributing

We welcome contributions and collaboration on this project. Please read our contributor's guide to understand how best to work with us.

License and Authors

Daniel James logo Daniel James

license GitHub contributors

This software is made available by Daniel James under the MIT license.