private async Task <IList> ExecuteOe <T, TResult>(LambdaExpression lambda, int maxPageSize) { Container container = CreateContainer(maxPageSize); var visitor = new TypeMapperVisitor(container) { TypeMap = t => Type.GetType("ODataClient." + t.FullName) }; var call = visitor.Visit(lambda.Body); IQueryable query = GetQuerableOe(container, typeof(T)); Type elementType; if (call.Type.GetTypeInfo().IsGenericType) { elementType = call.Type.GetGenericArguments()[0]; ExecuteQueryFuncAsync <Object> func = ExecuteQueryAsync <Object>; return(await CreateDelegate(elementType, func)(query, call, visitor.NavigationPropertyAccessors)); } else { elementType = typeof(Object); ExecuteQueryFunc <Object> func = ExecuteQueryScalar <Object>; return(CreateDelegate(elementType, func)(query, call)); } }
private static ExecuteQueryFuncAsync <Object> CreateDelegate(Type elementType, ExecuteQueryFuncAsync <Object> execFunc) { MethodInfo execMethodInfo = execFunc.GetMethodInfo().GetGenericMethodDefinition().MakeGenericMethod(elementType); var execFuncType = execFunc.GetType().GetGenericTypeDefinition().MakeGenericType(elementType); return((ExecuteQueryFuncAsync <Object>)execMethodInfo.CreateDelegate(execFuncType)); }