Exemplo n.º 1
0
        public virtual ActionMethodModel BuildAction <TController>(Expression <Action <TController> > expression)
            where TController : IController
        {
            var methodCall = expression.Body as MethodCallExpression;

            if (methodCall == null)
            {
                throw new TypedActionException(
                          "The expression body must be a MethodCallExpression, " +
                          "that is, a lamda in the form of 'c => c.Action(optional, action, parameters)', " +
                          "where the action parameters can be anything you want (variable, property, method call etc.) " +
                          "as long as they return the right parameter and the function will compile.");
            }

            var actionMethod = methodCall.Method;

            if (false == actionMethod.DeclaringType.IsAssignableFrom(typeof(TController)))
            {
                throw new TypedActionException(
                          "Expression body must be a lambda with a call to a action method on the controller type '{0}', " +
                          "and can not be a call to '{1}.{2}'.",
                          typeof(TController).FullName, actionMethod.DeclaringType.FullName, actionMethod.Name);
            }

            var descriptor = GetDescriptor(typeof(TController));
            var model      = new ActionMethodModel(descriptor, actionMethod);

            SetActionParameters(model, methodCall);

            return(model);
        }
Exemplo n.º 2
0
        protected virtual void SetActionParameters(ActionMethodModel actionModel, MethodCallExpression methodCall)
        {
            var givenValues = GetGivenParameterValues(methodCall);

            var parameters = ParametersBuilder.BuildParameters(givenValues);

            actionModel.SetParameters(parameters);
        }
Exemplo n.º 3
0
 public virtual void Redirect(IRedirectSupport redirecter, ActionMethodModel action)
 {
     Redirect(redirecter, action.Area, action.Controller, action.Action, action.GetParameterDictionary());
 }