public ControllerTreeNode(AbstractController controller) { if (controller == null) throw new ArgumentNullException("controller"); this.Controller = controller; this.Text = controller.GetType().Name; this.Tag = controller; }
public ControllerTreeNode(AbstractController controller) { if (controller == null) { throw new ArgumentNullException("controller"); } this.Controller = controller; this.Text = controller.GetType().Name; this.Tag = controller; }
public AbstractView InvokeAction(AbstractController controller, string action, NameValueCollection parameters) { Type cType = controller.GetType(); var method = cType.GetMethods().FirstOrDefault(x => x.Name.ToLower() == action.ToLower()); if (method == null) { throw new HttpException(404, "Not Found"); } var paraInfos = method.GetParameters(); var keys = parameters.Keys.Cast <string>(); //this will contain the list of parameters in the correct order List <string> finalParams = new List <string>(); //get the paramaters in the correct order foreach (var paraInfo in paraInfos) { var key = keys.FirstOrDefault(x => x.ToLower() == paraInfo.Name.ToLower()); if (key.IsNotNullOrEmpty()) { finalParams.Add(parameters[key]); } //if we can find a parameter for the method throw a not found else { throw new HttpException(404, "Not Found"); } } var view = method.Invoke(controller, finalParams.ToArray()); if (view is AbstractView) { return(view as AbstractView); } else { throw new HttpException(500, "Incorrect view"); } }