private void ShowDLLExplorer(object sender, EventArgs e) { //create form frmDLLExplorer dllExplorer = new frmDLLExplorer(); //show dialog if (dllExplorer.ShowDialog() == DialogResult.OK) { //user accepted the selections //declare command ExecuteDLLCommand cmd = (ExecuteDLLCommand)_currentEditor.SelectedCommand; //add file name if (!string.IsNullOrEmpty(dllExplorer.FileName)) { _currentEditor.flw_InputVariables.Controls["v_FilePath"].Text = dllExplorer.FileName; } //add class name if (dllExplorer.lstClasses.SelectedItem != null) { _currentEditor.flw_InputVariables.Controls["v_ClassName"].Text = dllExplorer.lstClasses.SelectedItem.ToString(); } //add method name if (dllExplorer.lstMethods.SelectedItem != null) { _currentEditor.flw_InputVariables.Controls["v_MethodName"].Text = dllExplorer.lstMethods.SelectedItem.ToString(); } cmd.v_MethodParameters.Rows.Clear(); //add parameters if ((dllExplorer.lstParameters.Items.Count > 0) && (dllExplorer.lstParameters.Items[0].ToString() != "This method requires no parameters!")) { foreach (var param in dllExplorer.SelectedParameters) { cmd.v_MethodParameters.Rows.Add(param, ""); } } } }
private void GenerateDLLParameters(object sender, EventArgs e) { ExecuteDLLCommand cmd = (ExecuteDLLCommand)_currentEditor.SelectedCommand; var filePath = _currentEditor.flw_InputVariables.Controls["v_FilePath"].Text; var className = _currentEditor.flw_InputVariables.Controls["v_ClassName"].Text; var methodName = _currentEditor.flw_InputVariables.Controls["v_MethodName"].Text; DataGridView parameterBox = (DataGridView)_currentEditor.flw_InputVariables.Controls["v_MethodParameters"]; //clear all rows cmd.v_MethodParameters.Rows.Clear(); //Load Assembly try { Assembly requiredAssembly = Assembly.LoadFrom(filePath); //get type Type t = requiredAssembly.GetType(className); //verify type was found if (t == null) { MessageBox.Show("The class '" + className + "' was not found in assembly loaded at '" + filePath + "'", "Class Not Found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } //get method MethodInfo m = t.GetMethod(methodName); //verify method found if (m == null) { MessageBox.Show("The method '" + methodName + "' was not found in assembly loaded at '" + filePath + "'", "Method Not Found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } //get parameters var reqdParams = m.GetParameters(); if (reqdParams.Length > 0) { cmd.v_MethodParameters.Rows.Clear(); foreach (var param in reqdParams) { cmd.v_MethodParameters.Rows.Add(param.Name, ""); } } else { MessageBox.Show("There are no parameters required for this method!", "No Parameters Required", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("There was an error generating the parameters: " + ex.ToString()); } }