// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. using System.Collections.Generic; using System.Linq.Expressions; using System.Reflection; using System.Threading; using System.Threading.Tasks; namespace System.Linq { public static partial class AsyncQueryableEx { public static IAsyncQueryable> Buffer(this IAsyncQueryable source, int count) { if (source == null) throw new ArgumentNullException(nameof(source)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery>(Expression.Call(InfoOf(() => AsyncQueryableEx.Buffer(default(IAsyncQueryable), default(int))), source.Expression, Expression.Constant(count, typeof(int)))); #else return source.Provider.CreateQuery>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, Expression.Constant(count, typeof(int)))); #endif } public static IAsyncQueryable> Buffer(this IAsyncQueryable source, int count, int skip) { if (source == null) throw new ArgumentNullException(nameof(source)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery>(Expression.Call(InfoOf(() => AsyncQueryableEx.Buffer(default(IAsyncQueryable), default(int), default(int))), source.Expression, Expression.Constant(count, typeof(int)), Expression.Constant(skip, typeof(int)))); #else return source.Provider.CreateQuery>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, Expression.Constant(count, typeof(int)), Expression.Constant(skip, typeof(int)))); #endif } public static IAsyncQueryable Catch(this IAsyncQueryable source, Expression>> handler) { if (source == null) throw new ArgumentNullException(nameof(source)); if (handler == null) throw new ArgumentNullException(nameof(handler)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Catch(default(IAsyncQueryable), default(Expression>>))), source.Expression, handler)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TException)), source.Expression, handler)); #endif } public static IAsyncQueryable Catch(this IAsyncQueryable source, Expression>>> handler) { if (source == null) throw new ArgumentNullException(nameof(source)); if (handler == null) throw new ArgumentNullException(nameof(handler)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Catch(default(IAsyncQueryable), default(Expression>>>))), source.Expression, handler)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TException)), source.Expression, handler)); #endif } public static IAsyncQueryable Catch(this IAsyncQueryable first, IAsyncEnumerable second) { if (first == null) throw new ArgumentNullException(nameof(first)); if (second == null) throw new ArgumentNullException(nameof(second)); #if CRIPPLED_REFLECTION return first.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Catch(default(IAsyncQueryable), default(IAsyncEnumerable))), first.Expression, GetSourceExpression(second))); #else return first.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), first.Expression, GetSourceExpression(second))); #endif } public static IAsyncQueryable Distinct(this IAsyncQueryable source, Expression> keySelector) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Distinct(default(IAsyncQueryable), default(Expression>))), source.Expression, keySelector)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector)); #endif } public static IAsyncQueryable Distinct(this IAsyncQueryable source, Expression>> keySelector) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Distinct(default(IAsyncQueryable), default(Expression>>))), source.Expression, keySelector)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector)); #endif } public static IAsyncQueryable Distinct(this IAsyncQueryable source, Expression> keySelector, IEqualityComparer comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); if (comparer == null) throw new ArgumentNullException(nameof(comparer)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Distinct(default(IAsyncQueryable), default(Expression>), default(IEqualityComparer))), source.Expression, keySelector, Expression.Constant(comparer, typeof(IEqualityComparer)))); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector, Expression.Constant(comparer, typeof(IEqualityComparer)))); #endif } public static IAsyncQueryable Distinct(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); if (comparer == null) throw new ArgumentNullException(nameof(comparer)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Distinct(default(IAsyncQueryable), default(Expression>>), default(IEqualityComparer))), source.Expression, keySelector, Expression.Constant(comparer, typeof(IEqualityComparer)))); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector, Expression.Constant(comparer, typeof(IEqualityComparer)))); #endif } public static IAsyncQueryable DistinctUntilChanged(this IAsyncQueryable source) { if (source == null) throw new ArgumentNullException(nameof(source)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.DistinctUntilChanged(default(IAsyncQueryable))), source.Expression)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression)); #endif } public static IAsyncQueryable DistinctUntilChanged(this IAsyncQueryable source, IEqualityComparer comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); if (comparer == null) throw new ArgumentNullException(nameof(comparer)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.DistinctUntilChanged(default(IAsyncQueryable), default(IEqualityComparer))), source.Expression, Expression.Constant(comparer, typeof(IEqualityComparer)))); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, Expression.Constant(comparer, typeof(IEqualityComparer)))); #endif } public static IAsyncQueryable DistinctUntilChanged(this IAsyncQueryable source, Expression> keySelector) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.DistinctUntilChanged(default(IAsyncQueryable), default(Expression>))), source.Expression, keySelector)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector)); #endif } public static IAsyncQueryable DistinctUntilChanged(this IAsyncQueryable source, Expression>> keySelector) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.DistinctUntilChanged(default(IAsyncQueryable), default(Expression>>))), source.Expression, keySelector)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector)); #endif } public static IAsyncQueryable DistinctUntilChanged(this IAsyncQueryable source, Expression> keySelector, IEqualityComparer comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); if (comparer == null) throw new ArgumentNullException(nameof(comparer)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.DistinctUntilChanged(default(IAsyncQueryable), default(Expression>), default(IEqualityComparer))), source.Expression, keySelector, Expression.Constant(comparer, typeof(IEqualityComparer)))); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector, Expression.Constant(comparer, typeof(IEqualityComparer)))); #endif } public static IAsyncQueryable DistinctUntilChanged(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); if (comparer == null) throw new ArgumentNullException(nameof(comparer)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.DistinctUntilChanged(default(IAsyncQueryable), default(Expression>>), default(IEqualityComparer))), source.Expression, keySelector, Expression.Constant(comparer, typeof(IEqualityComparer)))); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector, Expression.Constant(comparer, typeof(IEqualityComparer)))); #endif } public static IAsyncQueryable Do(this IAsyncQueryable source, Expression> onNext) { if (source == null) throw new ArgumentNullException(nameof(source)); if (onNext == null) throw new ArgumentNullException(nameof(onNext)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Do(default(IAsyncQueryable), default(Expression>))), source.Expression, onNext)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, onNext)); #endif } public static IAsyncQueryable Do(this IAsyncQueryable source, Expression> onNext) { if (source == null) throw new ArgumentNullException(nameof(source)); if (onNext == null) throw new ArgumentNullException(nameof(onNext)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Do(default(IAsyncQueryable), default(Expression>))), source.Expression, onNext)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, onNext)); #endif } public static IAsyncQueryable Do(this IAsyncQueryable source, IObserver observer) { if (source == null) throw new ArgumentNullException(nameof(source)); if (observer == null) throw new ArgumentNullException(nameof(observer)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Do(default(IAsyncQueryable), default(IObserver))), source.Expression, Expression.Constant(observer, typeof(IObserver)))); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, Expression.Constant(observer, typeof(IObserver)))); #endif } public static IAsyncQueryable Do(this IAsyncQueryable source, Expression> onNext, Action onCompleted) { if (source == null) throw new ArgumentNullException(nameof(source)); if (onNext == null) throw new ArgumentNullException(nameof(onNext)); if (onCompleted == null) throw new ArgumentNullException(nameof(onCompleted)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Do(default(IAsyncQueryable), default(Expression>), default(Action))), source.Expression, onNext, Expression.Constant(onCompleted, typeof(Action)))); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, onNext, Expression.Constant(onCompleted, typeof(Action)))); #endif } public static IAsyncQueryable Do(this IAsyncQueryable source, Expression> onNext, Expression> onError) { if (source == null) throw new ArgumentNullException(nameof(source)); if (onNext == null) throw new ArgumentNullException(nameof(onNext)); if (onError == null) throw new ArgumentNullException(nameof(onError)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Do(default(IAsyncQueryable), default(Expression>), default(Expression>))), source.Expression, onNext, onError)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, onNext, onError)); #endif } public static IAsyncQueryable Do(this IAsyncQueryable source, Expression> onNext, Expression> onCompleted) { if (source == null) throw new ArgumentNullException(nameof(source)); if (onNext == null) throw new ArgumentNullException(nameof(onNext)); if (onCompleted == null) throw new ArgumentNullException(nameof(onCompleted)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Do(default(IAsyncQueryable), default(Expression>), default(Expression>))), source.Expression, onNext, onCompleted)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, onNext, onCompleted)); #endif } public static IAsyncQueryable Do(this IAsyncQueryable source, Expression> onNext, Expression> onError) { if (source == null) throw new ArgumentNullException(nameof(source)); if (onNext == null) throw new ArgumentNullException(nameof(onNext)); if (onError == null) throw new ArgumentNullException(nameof(onError)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Do(default(IAsyncQueryable), default(Expression>), default(Expression>))), source.Expression, onNext, onError)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, onNext, onError)); #endif } public static IAsyncQueryable Do(this IAsyncQueryable source, Expression> onNext, Expression> onError, Action onCompleted) { if (source == null) throw new ArgumentNullException(nameof(source)); if (onNext == null) throw new ArgumentNullException(nameof(onNext)); if (onError == null) throw new ArgumentNullException(nameof(onError)); if (onCompleted == null) throw new ArgumentNullException(nameof(onCompleted)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Do(default(IAsyncQueryable), default(Expression>), default(Expression>), default(Action))), source.Expression, onNext, onError, Expression.Constant(onCompleted, typeof(Action)))); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, onNext, onError, Expression.Constant(onCompleted, typeof(Action)))); #endif } public static IAsyncQueryable Do(this IAsyncQueryable source, Expression> onNext, Expression> onError, Expression> onCompleted) { if (source == null) throw new ArgumentNullException(nameof(source)); if (onNext == null) throw new ArgumentNullException(nameof(onNext)); if (onError == null) throw new ArgumentNullException(nameof(onError)); if (onCompleted == null) throw new ArgumentNullException(nameof(onCompleted)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Do(default(IAsyncQueryable), default(Expression>), default(Expression>), default(Expression>))), source.Expression, onNext, onError, onCompleted)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, onNext, onError, onCompleted)); #endif } public static IAsyncQueryable Expand(this IAsyncQueryable source, Expression>> selector) { if (source == null) throw new ArgumentNullException(nameof(source)); if (selector == null) throw new ArgumentNullException(nameof(selector)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Expand(default(IAsyncQueryable), default(Expression>>))), source.Expression, selector)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, selector)); #endif } public static IAsyncQueryable Expand(this IAsyncQueryable source, Expression>>> selector) { if (source == null) throw new ArgumentNullException(nameof(source)); if (selector == null) throw new ArgumentNullException(nameof(selector)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Expand(default(IAsyncQueryable), default(Expression>>>))), source.Expression, selector)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, selector)); #endif } public static IAsyncQueryable Finally(this IAsyncQueryable source, Action finallyAction) { if (source == null) throw new ArgumentNullException(nameof(source)); if (finallyAction == null) throw new ArgumentNullException(nameof(finallyAction)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Finally(default(IAsyncQueryable), default(Action))), source.Expression, Expression.Constant(finallyAction, typeof(Action)))); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, Expression.Constant(finallyAction, typeof(Action)))); #endif } public static IAsyncQueryable Finally(this IAsyncQueryable source, Expression> finallyAction) { if (source == null) throw new ArgumentNullException(nameof(source)); if (finallyAction == null) throw new ArgumentNullException(nameof(finallyAction)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Finally(default(IAsyncQueryable), default(Expression>))), source.Expression, finallyAction)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, finallyAction)); #endif } public static IAsyncQueryable IgnoreElements(this IAsyncQueryable source) { if (source == null) throw new ArgumentNullException(nameof(source)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.IgnoreElements(default(IAsyncQueryable))), source.Expression)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression)); #endif } public static Task IsEmpty(this IAsyncQueryable source) { if (source == null) throw new ArgumentNullException(nameof(source)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync(Expression.Call(InfoOf(() => AsyncQueryableEx.IsEmpty(default(IAsyncQueryable))), source.Expression), CancellationToken.None); #else return source.Provider.ExecuteAsync(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression), CancellationToken.None); #endif } public static Task IsEmpty(this IAsyncQueryable source, CancellationToken cancellationToken) { if (source == null) throw new ArgumentNullException(nameof(source)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync(Expression.Call(InfoOf(() => AsyncQueryableEx.IsEmpty(default(IAsyncQueryable), default(CancellationToken))), source.Expression, Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #else return source.Provider.ExecuteAsync(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #endif } public static Task Max(this IAsyncQueryable source, IComparer comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); if (comparer == null) throw new ArgumentNullException(nameof(comparer)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync(Expression.Call(InfoOf(() => AsyncQueryableEx.Max(default(IAsyncQueryable), default(IComparer))), source.Expression, Expression.Constant(comparer, typeof(IComparer))), CancellationToken.None); #else return source.Provider.ExecuteAsync(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, Expression.Constant(comparer, typeof(IComparer))), CancellationToken.None); #endif } public static Task Max(this IAsyncQueryable source, IComparer comparer, CancellationToken cancellationToken) { if (source == null) throw new ArgumentNullException(nameof(source)); if (comparer == null) throw new ArgumentNullException(nameof(comparer)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync(Expression.Call(InfoOf(() => AsyncQueryableEx.Max(default(IAsyncQueryable), default(IComparer), default(CancellationToken))), source.Expression, Expression.Constant(comparer, typeof(IComparer)), Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #else return source.Provider.ExecuteAsync(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, Expression.Constant(comparer, typeof(IComparer)), Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #endif } public static Task> MaxBy(this IAsyncQueryable source, Expression> keySelector) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync>(Expression.Call(InfoOf(() => AsyncQueryableEx.MaxBy(default(IAsyncQueryable), default(Expression>))), source.Expression, keySelector), CancellationToken.None); #else return source.Provider.ExecuteAsync>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector), CancellationToken.None); #endif } public static Task> MaxBy(this IAsyncQueryable source, Expression>> keySelector) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync>(Expression.Call(InfoOf(() => AsyncQueryableEx.MaxBy(default(IAsyncQueryable), default(Expression>>))), source.Expression, keySelector), CancellationToken.None); #else return source.Provider.ExecuteAsync>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector), CancellationToken.None); #endif } public static Task> MaxBy(this IAsyncQueryable source, Expression>> keySelector, CancellationToken cancellationToken) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync>(Expression.Call(InfoOf(() => AsyncQueryableEx.MaxBy(default(IAsyncQueryable), default(Expression>>), default(CancellationToken))), source.Expression, keySelector, Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #else return source.Provider.ExecuteAsync>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector, Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #endif } public static Task> MaxBy(this IAsyncQueryable source, Expression>> keySelector, IComparer comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); if (comparer == null) throw new ArgumentNullException(nameof(comparer)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync>(Expression.Call(InfoOf(() => AsyncQueryableEx.MaxBy(default(IAsyncQueryable), default(Expression>>), default(IComparer))), source.Expression, keySelector, Expression.Constant(comparer, typeof(IComparer))), CancellationToken.None); #else return source.Provider.ExecuteAsync>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector, Expression.Constant(comparer, typeof(IComparer))), CancellationToken.None); #endif } public static Task> MaxBy(this IAsyncQueryable source, Expression> keySelector, CancellationToken cancellationToken) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync>(Expression.Call(InfoOf(() => AsyncQueryableEx.MaxBy(default(IAsyncQueryable), default(Expression>), default(CancellationToken))), source.Expression, keySelector, Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #else return source.Provider.ExecuteAsync>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector, Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #endif } public static Task> MaxBy(this IAsyncQueryable source, Expression> keySelector, IComparer comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); if (comparer == null) throw new ArgumentNullException(nameof(comparer)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync>(Expression.Call(InfoOf(() => AsyncQueryableEx.MaxBy(default(IAsyncQueryable), default(Expression>), default(IComparer))), source.Expression, keySelector, Expression.Constant(comparer, typeof(IComparer))), CancellationToken.None); #else return source.Provider.ExecuteAsync>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector, Expression.Constant(comparer, typeof(IComparer))), CancellationToken.None); #endif } public static Task> MaxBy(this IAsyncQueryable source, Expression>> keySelector, IComparer comparer, CancellationToken cancellationToken) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); if (comparer == null) throw new ArgumentNullException(nameof(comparer)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync>(Expression.Call(InfoOf(() => AsyncQueryableEx.MaxBy(default(IAsyncQueryable), default(Expression>>), default(IComparer), default(CancellationToken))), source.Expression, keySelector, Expression.Constant(comparer, typeof(IComparer)), Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #else return source.Provider.ExecuteAsync>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector, Expression.Constant(comparer, typeof(IComparer)), Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #endif } public static Task> MaxBy(this IAsyncQueryable source, Expression> keySelector, IComparer comparer, CancellationToken cancellationToken) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); if (comparer == null) throw new ArgumentNullException(nameof(comparer)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync>(Expression.Call(InfoOf(() => AsyncQueryableEx.MaxBy(default(IAsyncQueryable), default(Expression>), default(IComparer), default(CancellationToken))), source.Expression, keySelector, Expression.Constant(comparer, typeof(IComparer)), Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #else return source.Provider.ExecuteAsync>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector, Expression.Constant(comparer, typeof(IComparer)), Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #endif } public static Task Min(this IAsyncQueryable source, IComparer comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); if (comparer == null) throw new ArgumentNullException(nameof(comparer)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync(Expression.Call(InfoOf(() => AsyncQueryableEx.Min(default(IAsyncQueryable), default(IComparer))), source.Expression, Expression.Constant(comparer, typeof(IComparer))), CancellationToken.None); #else return source.Provider.ExecuteAsync(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, Expression.Constant(comparer, typeof(IComparer))), CancellationToken.None); #endif } public static Task Min(this IAsyncQueryable source, IComparer comparer, CancellationToken cancellationToken) { if (source == null) throw new ArgumentNullException(nameof(source)); if (comparer == null) throw new ArgumentNullException(nameof(comparer)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync(Expression.Call(InfoOf(() => AsyncQueryableEx.Min(default(IAsyncQueryable), default(IComparer), default(CancellationToken))), source.Expression, Expression.Constant(comparer, typeof(IComparer)), Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #else return source.Provider.ExecuteAsync(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, Expression.Constant(comparer, typeof(IComparer)), Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #endif } public static Task> MinBy(this IAsyncQueryable source, Expression> keySelector) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync>(Expression.Call(InfoOf(() => AsyncQueryableEx.MinBy(default(IAsyncQueryable), default(Expression>))), source.Expression, keySelector), CancellationToken.None); #else return source.Provider.ExecuteAsync>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector), CancellationToken.None); #endif } public static Task> MinBy(this IAsyncQueryable source, Expression>> keySelector) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync>(Expression.Call(InfoOf(() => AsyncQueryableEx.MinBy(default(IAsyncQueryable), default(Expression>>))), source.Expression, keySelector), CancellationToken.None); #else return source.Provider.ExecuteAsync>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector), CancellationToken.None); #endif } public static Task> MinBy(this IAsyncQueryable source, Expression> keySelector, CancellationToken cancellationToken) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync>(Expression.Call(InfoOf(() => AsyncQueryableEx.MinBy(default(IAsyncQueryable), default(Expression>), default(CancellationToken))), source.Expression, keySelector, Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #else return source.Provider.ExecuteAsync>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector, Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #endif } public static Task> MinBy(this IAsyncQueryable source, Expression> keySelector, IComparer comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); if (comparer == null) throw new ArgumentNullException(nameof(comparer)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync>(Expression.Call(InfoOf(() => AsyncQueryableEx.MinBy(default(IAsyncQueryable), default(Expression>), default(IComparer))), source.Expression, keySelector, Expression.Constant(comparer, typeof(IComparer))), CancellationToken.None); #else return source.Provider.ExecuteAsync>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector, Expression.Constant(comparer, typeof(IComparer))), CancellationToken.None); #endif } public static Task> MinBy(this IAsyncQueryable source, Expression>> keySelector, CancellationToken cancellationToken) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync>(Expression.Call(InfoOf(() => AsyncQueryableEx.MinBy(default(IAsyncQueryable), default(Expression>>), default(CancellationToken))), source.Expression, keySelector, Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #else return source.Provider.ExecuteAsync>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector, Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #endif } public static Task> MinBy(this IAsyncQueryable source, Expression>> keySelector, IComparer comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); if (comparer == null) throw new ArgumentNullException(nameof(comparer)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync>(Expression.Call(InfoOf(() => AsyncQueryableEx.MinBy(default(IAsyncQueryable), default(Expression>>), default(IComparer))), source.Expression, keySelector, Expression.Constant(comparer, typeof(IComparer))), CancellationToken.None); #else return source.Provider.ExecuteAsync>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector, Expression.Constant(comparer, typeof(IComparer))), CancellationToken.None); #endif } public static Task> MinBy(this IAsyncQueryable source, Expression> keySelector, IComparer comparer, CancellationToken cancellationToken) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); if (comparer == null) throw new ArgumentNullException(nameof(comparer)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync>(Expression.Call(InfoOf(() => AsyncQueryableEx.MinBy(default(IAsyncQueryable), default(Expression>), default(IComparer), default(CancellationToken))), source.Expression, keySelector, Expression.Constant(comparer, typeof(IComparer)), Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #else return source.Provider.ExecuteAsync>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector, Expression.Constant(comparer, typeof(IComparer)), Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #endif } public static Task> MinBy(this IAsyncQueryable source, Expression>> keySelector, IComparer comparer, CancellationToken cancellationToken) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); if (comparer == null) throw new ArgumentNullException(nameof(comparer)); #if CRIPPLED_REFLECTION return source.Provider.ExecuteAsync>(Expression.Call(InfoOf(() => AsyncQueryableEx.MinBy(default(IAsyncQueryable), default(Expression>>), default(IComparer), default(CancellationToken))), source.Expression, keySelector, Expression.Constant(comparer, typeof(IComparer)), Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #else return source.Provider.ExecuteAsync>(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), source.Expression, keySelector, Expression.Constant(comparer, typeof(IComparer)), Expression.Constant(cancellationToken, typeof(CancellationToken))), cancellationToken); #endif } public static IAsyncQueryable OnErrorResumeNext(this IAsyncQueryable first, IAsyncEnumerable second) { if (first == null) throw new ArgumentNullException(nameof(first)); if (second == null) throw new ArgumentNullException(nameof(second)); #if CRIPPLED_REFLECTION return first.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.OnErrorResumeNext(default(IAsyncQueryable), default(IAsyncEnumerable))), first.Expression, GetSourceExpression(second))); #else return first.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), first.Expression, GetSourceExpression(second))); #endif } public static IAsyncQueryable Repeat(this IAsyncQueryable source) { if (source == null) throw new ArgumentNullException(nameof(source)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Repeat(default(IAsyncQueryable))), source.Expression)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression)); #endif } public static IAsyncQueryable Repeat(this IAsyncQueryable source, int count) { if (source == null) throw new ArgumentNullException(nameof(source)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Repeat(default(IAsyncQueryable), default(int))), source.Expression, Expression.Constant(count, typeof(int)))); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, Expression.Constant(count, typeof(int)))); #endif } public static IAsyncQueryable Retry(this IAsyncQueryable source) { if (source == null) throw new ArgumentNullException(nameof(source)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Retry(default(IAsyncQueryable))), source.Expression)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression)); #endif } public static IAsyncQueryable Retry(this IAsyncQueryable source, int retryCount) { if (source == null) throw new ArgumentNullException(nameof(source)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Retry(default(IAsyncQueryable), default(int))), source.Expression, Expression.Constant(retryCount, typeof(int)))); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, Expression.Constant(retryCount, typeof(int)))); #endif } public static IAsyncQueryable Scan(this IAsyncQueryable source, Expression> accumulator) { if (source == null) throw new ArgumentNullException(nameof(source)); if (accumulator == null) throw new ArgumentNullException(nameof(accumulator)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Scan(default(IAsyncQueryable), default(Expression>))), source.Expression, accumulator)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, accumulator)); #endif } public static IAsyncQueryable Scan(this IAsyncQueryable source, Expression>> accumulator) { if (source == null) throw new ArgumentNullException(nameof(source)); if (accumulator == null) throw new ArgumentNullException(nameof(accumulator)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Scan(default(IAsyncQueryable), default(Expression>>))), source.Expression, accumulator)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, accumulator)); #endif } public static IAsyncQueryable Scan(this IAsyncQueryable source, TAccumulate seed, Expression> accumulator) { if (source == null) throw new ArgumentNullException(nameof(source)); if (accumulator == null) throw new ArgumentNullException(nameof(accumulator)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Scan(default(IAsyncQueryable), default(TAccumulate), default(Expression>))), source.Expression, Expression.Constant(seed, typeof(TAccumulate)), accumulator)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TAccumulate)), source.Expression, Expression.Constant(seed, typeof(TAccumulate)), accumulator)); #endif } public static IAsyncQueryable Scan(this IAsyncQueryable source, TAccumulate seed, Expression>> accumulator) { if (source == null) throw new ArgumentNullException(nameof(source)); if (accumulator == null) throw new ArgumentNullException(nameof(accumulator)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.Scan(default(IAsyncQueryable), default(TAccumulate), default(Expression>>))), source.Expression, Expression.Constant(seed, typeof(TAccumulate)), accumulator)); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TAccumulate)), source.Expression, Expression.Constant(seed, typeof(TAccumulate)), accumulator)); #endif } public static IAsyncQueryable SelectMany(this IAsyncQueryable source, IAsyncEnumerable other) { if (source == null) throw new ArgumentNullException(nameof(source)); if (other == null) throw new ArgumentNullException(nameof(other)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.SelectMany(default(IAsyncQueryable), default(IAsyncEnumerable))), source.Expression, GetSourceExpression(other))); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TOther)), source.Expression, GetSourceExpression(other))); #endif } public static IAsyncQueryable StartWith(this IAsyncQueryable source, params TSource[] values) { if (source == null) throw new ArgumentNullException(nameof(source)); if (values == null) throw new ArgumentNullException(nameof(values)); #if CRIPPLED_REFLECTION return source.Provider.CreateQuery(Expression.Call(InfoOf(() => AsyncQueryableEx.StartWith(default(IAsyncQueryable), default(TSource[]))), source.Expression, Expression.Constant(values, typeof(TSource[])))); #else return source.Provider.CreateQuery(Expression.Call(((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), source.Expression, Expression.Constant(values, typeof(TSource[])))); #endif } } }