/// <summary> /// TestMethodory method for returning a request processor /// </summary> /// <typeparam name="T">type of request</typeparam> /// <returns>request processor matching type parameter</returns> internal IRequestProcessor <T> CreateRequestProcessor <T>(Expression expression) where T : class { _ = expression ?? throw new ArgumentNullException(nameof(expression), "Expression passed to CreateRequestProcessor must not be null."); Type?genericType = new MethodCallExpressionTypeFinder().GetGenericType(expression); _ = genericType ?? throw new ArgumentNullException(nameof(expression), "Generic type of Expression passed to CreateRequestProcessor must not be null."); return(CreateRequestProcessor <T>(genericType.Name)); }
internal IRequestProcessor <T> CreateRequestProcessor <T>(Expression expression) where T : class { if (expression == null) { throw new ArgumentNullException( nameof(expression), "Expression passed to CreateRequestProcessor must not be null."); } string requestType = new MethodCallExpressionTypeFinder().GetGenericType(expression).Name; return(CreateRequestProcessor <T>(requestType)); }
/// <summary> /// TestMethodory method for returning a request processor /// </summary> /// <typeparam name="T">type of request</typeparam> /// <returns>request processor matching type parameter</returns> internal IRequestProcessor <T> CreateRequestProcessor <T>(Expression expression) where T : class { if (expression == null) { const string NullExpressionMessage = "Expression passed to CreateRequestProcessor must not be null."; throw new ArgumentNullException("Expression", NullExpressionMessage); } string requestType = new MethodCallExpressionTypeFinder().GetGenericType(expression).Name; IRequestProcessor <T> req = CreateRequestProcessor <T>(requestType); return(req); }
/// <summary> /// generic execute, delegates execution to TwitterContext /// </summary> /// <typeparam name="TResult">type of query</typeparam> /// <param name="expression">Expression tree</param> /// <returns>list of results from query</returns> public TResult Execute <TResult>(Expression expression) { bool isEnumerable = typeof(TResult).Name == "IEnumerable`1" || typeof(TResult).Name == "IEnumerable"; // generic parameter type for method call Type resultType = new MethodCallExpressionTypeFinder().GetGenericType(expression); Type[] genericArguments = new Type[] { resultType }; // generic method instance via reflection var methodInfo = Context.GetType().GetMethod("Execute", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); MethodInfo genericMethodInfo = methodInfo.MakeGenericMethod(genericArguments); // use reflection to execute the generic method with the proper arguments // Note: look at ProcessResults method in PostProcessor and you'll see what is being executed return((TResult)genericMethodInfo.Invoke(Context, new object[] { expression, isEnumerable })); }