TaskLinq
enables you to use method-chaining of LINQ methods when returning enumerable objects from an async method.
IEnumerable<T>
, List<T>
, and T[]
are all supported natively. For other enumerable types, you can call AsEnumerableAsync()
to continue using the chained methods.
Install the package from NuGet with dotnet add package TaskLinq
.
Instead of doing this:
var values = (await GetValuesAsync()).ToArray();
you can do this:
var values = await GetValuesAsync().ToArrayAsync();
You can also chain LINQ methods together and await
the entire chain:
var values = await GetValuesAsync()
.WhereAsync(x => x > 1)
.OrderByAsync(x => x)
.ToArrayAsync();
For other types inheriting IEnumerable<T>
such as HashSet<T>
and Dictionary<TKey, TValue>
, you can use AsEnumerableAsync()
and continue method-chaining:
var values = await GetMyCustomCollection()
.AsEnumerableAsync()
.ToArrayAsync();
Raise an issue.
Please read CONTRIBUTING.md for details on how to contribute to this project.
TaskLinq is released under the MIT License