Skip to content

Instantly share code, notes, and snippets.

@madmonkey
Created November 21, 2023 20:02
Show Gist options
  • Save madmonkey/733f5cb39f63217d34f678d0f937b92b to your computer and use it in GitHub Desktop.
Save madmonkey/733f5cb39f63217d34f678d0f937b92b to your computer and use it in GitHub Desktop.
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