public MethodParamForm(MethodCallInfo methodInfo) { _methodCallInfo = methodInfo; InitializeComponent(); lblMethodTitle.Text = string.Format("{0} : {1}", methodInfo.MethodSignatureShort, methodInfo.ReturnType.Name); this.Parameters = new List<object>(); _parameterControls = new List<Control>(); int rowIndex = 0; foreach (var parameter in methodInfo.Parameters) { var lbl = new Label(); tableLayoutPanel1.Controls.Add(lbl, 0, rowIndex); lbl.Dock = DockStyle.Fill; lbl.Text = string.Format("{0} : {1}", parameter.Name, parameter.ParameterType.Name); var ctrl = ParameterControlFactory.GetControl(parameter); tableLayoutPanel1.Controls.Add(ctrl, 1, rowIndex); ctrl.Dock = DockStyle.Fill; _parameterControls.Add(ctrl); rowIndex++; } }
private Button GetButtonFromMethod(MethodCallInfo method, int width, int height) { var btn = new Button(); //btn.Text = method.DisplayName; btn.Text = string.Format("{0} : {1}", method.MethodSignatureShort, method.ReturnType.Name); btn.Left = 0; btn.Height = height; btn.Width = width; btn.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; btn.Click += (s, e) => { object returnObject = null; List<object> parameters = null; if (method.HasParameters) { using (var form = new MethodParamForm(method)) { if (form.ShowDialog() == DialogResult.OK) { try { method.Invoke(form.Parameters, out returnObject); } catch (Exception ex) { Dump(ex); tbMethodLog.AppendText(string.Format("{0} ⇒ Exception: {1}\r\n", method.Name, ex.Message)); return; } } else { return; } } } else { try { method.Invoke(null, out returnObject); } catch (Exception ex) { Dump(ex); tbMethodLog.AppendText(string.Format("{0} ⇒ Exception: {1}\r\n", method.Name, ex.Message)); return; } } Dump(returnObject); tbMethodLog.AppendText(string.Format("{0} ⇒ {1}\r\n", method.Name, returnObject ?? "null")); // Update board control gameBoardViewer1.Invalidate(); }; return btn; }