public void Intercept(IInvocation invocation) { // Build Request var methodInfo = new RestMethodInfo(invocation.Method); // TODO: Memoize these objects in a hash for performance var request = new RequestBuilder(methodInfo, invocation.Arguments).Build(); // Execute request var responseType = invocation.Method.ReturnType; var genericTypeArgument = responseType.GenericTypeArguments[0]; // We have to find the method manually due to limitations of GetMethod() var methods = restClient.GetType().GetMethods(); MethodInfo method = methods.Where(m => m.Name == "Execute").First(m => m.IsGenericMethod); MethodInfo generic = method.MakeGenericMethod(genericTypeArgument); invocation.ReturnValue = generic.Invoke(restClient, new object[] { request }); }
public RequestBuilder(RestMethodInfo methodInfo, object[] arguments) { this.methodInfo = methodInfo; this.arguments = arguments; }