Empty.cs 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Collections.Generic;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. namespace System.Linq
  8. {
  9. public static partial class AsyncEnumerable
  10. {
  11. public static IAsyncEnumerable<TValue> Empty<TValue>()
  12. {
  13. return new EmptyAsyncIterator<TValue>();
  14. }
  15. private sealed class EmptyAsyncIterator<TValue> : AsyncIterator<TValue>, IAsyncIListProvider<TValue>
  16. {
  17. public override AsyncIterator<TValue> Clone() => new EmptyAsyncIterator<TValue>();
  18. public Task<int> GetCountAsync(bool onlyIfCheap, CancellationToken cancellationToken) => Task.FromResult(0);
  19. public Task<TValue[]> ToArrayAsync(CancellationToken cancellationToken) => Task.FromResult(Array.Empty<TValue>());
  20. public Task<List<TValue>> ToListAsync(CancellationToken cancellationToken) => Task.FromResult(new List<TValue>());
  21. protected override Task<bool> MoveNextCore() => TaskExt.False;
  22. }
  23. }
  24. }