using System; using System.Collections.Generic; using System.Threading.Tasks; namespace Mvc.Server.Helpers { public static class AsyncEnumerableExtensions { public static Task> ToListAsync(this IAsyncEnumerable source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return ExecuteAsync(); async Task> ExecuteAsync() { var list = new List(); await foreach (var element in source) { list.Add(element); } return list; } } } }