-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add task extensions to enumerate IEnumerable<T>s * Fix build warning by checking count as well * Add NuGet metadata to new package
- Loading branch information
Tomas Lycken
authored
Nov 1, 2017
1 parent
fd9ef32
commit 1b02e36
Showing
3 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace System.Threading.Tasks | ||
{ | ||
public static class TaskExtensions | ||
{ | ||
/// <summary> | ||
/// Appends a continuation to the task, which iterates the resulting <see cref="IEnumerable{T}"/> into a <see cref="List{T}"/>. | ||
/// </summary> | ||
public static Task<List<T>> ToList<T>(this Task<IEnumerable<T>> task) | ||
=> task.ContinueWith(t => t.Result.ToList()); | ||
|
||
/// <summary> | ||
/// Appends a continuation to the task, which iterates the resulting <see cref="IEnumerable{T}"/> into a <see cref="List{T}"/> | ||
/// and returns it as an <see cref="IReadOnlyCollection{T}"/>. | ||
/// </summary> | ||
public static Task<IReadOnlyCollection<T>> ToReadOnlyCollection<T>(this Task<IEnumerable<T>> task) | ||
=> task.ContinueWith(t => t.Result.ToList() as IReadOnlyCollection<T>); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters