1
0

AsyncQueryable.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
  2. using System.Collections.Generic;
  3. using System.Linq.Expressions;
  4. namespace System.Linq
  5. {
  6. /// <summary>
  7. /// Provides a set of extension methods for asynchronous enumerable sequences represented using expression trees.
  8. /// </summary>
  9. public static partial class AsyncQueryable
  10. {
  11. /// <summary>
  12. /// Converts the specified asynchronous enumerable sequence to an expression representation.
  13. /// </summary>
  14. /// <typeparam name="TElement">The type of the elements in the sequence.</typeparam>
  15. /// <param name="source">The asynchronous enumerable sequence to represent using an expression tree.</param>
  16. /// <returns>An asynchronous enumerable sequence using an expression tree to represent the specified asynchronous enumerable sequence.</returns>
  17. public static IAsyncQueryable<TElement> AsAsyncQueryable<TElement>(this IAsyncEnumerable<TElement> source)
  18. {
  19. if (source == null)
  20. throw new ArgumentNullException("source");
  21. var queryable = source as IAsyncQueryable<TElement>;
  22. if (queryable != null)
  23. {
  24. return queryable;
  25. }
  26. return new AsyncEnumerableQuery<TElement>(source);
  27. }
  28. private static Expression GetSourceExpression<TSource>(IAsyncEnumerable<TSource> source)
  29. {
  30. var queryable = source as IAsyncQueryable<TSource>;
  31. if (queryable != null)
  32. {
  33. return queryable.Expression;
  34. }
  35. return Expression.Constant(source, typeof(IAsyncEnumerable<TSource>));
  36. }
  37. }
  38. }