Created
November 21, 2023 20:02
-
-
Save madmonkey/733f5cb39f63217d34f678d0f937b92b to your computer and use it in GitHub Desktop.
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
public static class AsyncEnumerableExtensions | |
{ | |
public static Task<List<T>> ToListAsync<T>(this IAsyncEnumerable<T> source) | |
{ | |
if (source == null) | |
{ | |
throw new ArgumentNullException(nameof(source)); | |
} | |
return ExecuteAsync(); | |
async Task<List<T>> ExecuteAsync() | |
{ | |
var list = new List<T>(); | |
await foreach (var element in source) | |
{ | |
list.Add(element); | |
} | |
return list; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment