Cast.cs 983 B

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;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. namespace System.Linq
  9. {
  10. public static partial class AsyncEnumerable
  11. {
  12. public static IAsyncEnumerable<TResult> Cast<TResult>(this IAsyncEnumerable<object> source)
  13. {
  14. if (source == null)
  15. throw new ArgumentNullException(nameof(source));
  16. return source.Select(x => (TResult)x);
  17. }
  18. public static IAsyncEnumerable<TType> OfType<TType>(this IAsyncEnumerable<object> source)
  19. {
  20. if (source == null)
  21. throw new ArgumentNullException(nameof(source));
  22. return source.Where(x => x is TType)
  23. .Cast<TType>();
  24. }
  25. }
  26. }