private static MethodCallExpression AggCallExpression(AggregationMethod aggMethod, ParameterExpression sourceParameter, LambdaExpression lambda) { String methodName; switch (aggMethod) { case AggregationMethod.Average: methodName = nameof(Enumerable.Average); break; case AggregationMethod.CountDistinct: return(CountDistinctExpression(sourceParameter, lambda)); case AggregationMethod.Max: methodName = nameof(Enumerable.Max); break; case AggregationMethod.Min: methodName = nameof(Enumerable.Min); break; case AggregationMethod.Sum: methodName = nameof(Enumerable.Sum); break; case AggregationMethod.VirtualPropertyCount: return(CountExpression(sourceParameter)); default: throw new NotSupportedException(); } MethodInfo closeMethod; MethodInfo openMethod = OeMethodInfoHelper.GetAggMethodInfo(methodName, lambda.ReturnType); if (openMethod.GetGenericArguments().Length == 1) { closeMethod = openMethod.MakeGenericMethod(lambda.Parameters[0].Type); } else { closeMethod = openMethod.MakeGenericMethod(lambda.Parameters[0].Type, lambda.ReturnType); } return(Expression.Call(closeMethod, sourceParameter, lambda)); }
private static MethodCallExpression AggCallExpression(AggregationMethod aggMethod, ParameterExpression sourceParameter, LambdaExpression lambda) { String methodName; switch (aggMethod) { case AggregationMethod.Average: methodName = nameof(Enumerable.Average); break; case AggregationMethod.CountDistinct: return(CountDistinctExpression(sourceParameter, lambda)); case AggregationMethod.Max: methodName = nameof(Enumerable.Max); break; case AggregationMethod.Min: methodName = nameof(Enumerable.Min); break; case AggregationMethod.Sum: methodName = nameof(Enumerable.Sum); break; case AggregationMethod.VirtualPropertyCount: return(CountExpression(sourceParameter)); default: throw new NotSupportedException(); } MethodInfo closeMethod; MethodInfo openMethod = OeMethodInfoHelper.GetAggMethodInfo(methodName, lambda.ReturnType); if (openMethod == null) { Func <IEnumerable <Object>, Func <Object, Object>, Object> aggFunc; switch (aggMethod) { case AggregationMethod.Max: aggFunc = Enumerable.Max; break; case AggregationMethod.Min: aggFunc = Enumerable.Min; break; default: throw new InvalidOperationException($"Enumerable.{methodName} not found");; } openMethod = aggFunc.GetMethodInfo().GetGenericMethodDefinition(); closeMethod = openMethod.MakeGenericMethod(lambda.Parameters[0].Type, lambda.ReturnType); } else { closeMethod = openMethod.MakeGenericMethod(lambda.Parameters[0].Type); } return(Expression.Call(closeMethod, sourceParameter, lambda)); }