You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
720 B
31 lines
720 B
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Mvc.Server.Helpers
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|