public void BindParameters(ActionDescriptor actionDescriptor, IDictionary<string, object> environment, IEnumerable<MediaTypeFormatter> formatters)
 {
     var queryString = environment["owin.RequestQueryString"] as string;
     if (queryString == null)
         throw new ArgumentNullException("environment[\"owin.RequestQueryString\"]");
     var queryParameters = GenerateQueryParameter(queryString);
     foreach (var param in actionDescriptor.ActionArguments)
         BindParameter(queryParameters, param);
 }
 /// <summary>
 /// Generates action descriptor from controller
 /// </summary>
 /// <param name="controller"></param>
 /// <returns></returns>
 public ActionDescriptor GenerateActionDescriptor(RestController controller)
 {
     var actionDescriptor = new ActionDescriptor(controller.Route.ActionName);
     var action = GetActionMethodInfo(controller, actionDescriptor.ActionName);
     if (action == null)
         return null;
     MapActionParameters(actionDescriptor, action);
     return actionDescriptor;
 }
        private async Task<object> InvokeActionAsync(RestController controller, ActionDescriptor descriptor)
        {
            var controllerType = controller.GetType();
            var actionMethod = controllerType.GetMethod(descriptor.ActionName);
            var result = actionMethod.Invoke(controller, descriptor.ActionArguments.Select(a => a.ParamValue).ToArray());
            if (result == null)
                result = (object)DBNull.Value;

            return await Task.FromResult(result);
        }
        public void TestMethod1()
        {
            int labasValue = 121;
            var queryString = "labas="+labasValue+"&iki=qwe";
            IDictionary<string, object> environment = new Dictionary<string, object>();
            environment.Add("owin.RequestQueryString", queryString);
            var paramBinder = new ActionParameterBinder();
            var actionDescriptor = new ActionDescriptor("test");
            actionDescriptor.ActionArguments.Add(new ActionArgumentDescriptor("labas", typeof(int), null));
            paramBinder.BindParameters(actionDescriptor, environment, new List<MediaTypeFormatter>());

            Assert.AreEqual(actionDescriptor.ActionArguments[0].ParamValue, labasValue);
        }
 /// <summary>
 /// Maps action MethodInfo parameters to action descriptor
 /// </summary>
 /// <param name="descriptor"></param>
 /// <param name="action"></param>
 public void MapActionParameters(ActionDescriptor descriptor, MethodInfo action)
 {
     foreach (var parameter in action.GetParameters())
         descriptor.ActionArguments.Add(new ActionArgumentDescriptor(parameter.Name, parameter.ParameterType, parameter.HasDefaultValue ? parameter.DefaultValue : null));
 }