private void btnOK_Click(object sender, EventArgs e)
        {
            MethodDefinition md = _frmClassView.SelectedMethod;

            if (md == null)
            {
                SimpleMessage.ShowInfo("Please choose a method");
                return;
            }

            bool resolveDirAdded = false;

            try
            {
                Utils.EnableUI(this.Controls, false);
                resolveDirAdded = _host.AddAssemblyResolveDir(_sourceDir);

                //string path = _rows[0];
                MethodBase mb = AssemblyUtils.ResolveMethod(md);

                object[] p = new object[_parameters.Rows.Count];

                for (int i = 0; i < _parameters.Rows.Count; i++)
                {
                    string s;
                    s = _parameters.Rows[i]["value"] == null ? String.Empty : _parameters.Rows[i]["value"].ToString();
                    if (!String.IsNullOrEmpty(s) && s.IndexOf("\\u") >= 0)
                    {
                        try
                        {
                            s = SimpleParse.ParseUnicodeString(s);
                        }
                        catch
                        {
                        }
                    }

                    string paramType = _parameters.Rows[i]["type"].ToString();
                    switch (paramType)
                    {
                    case "System.String":
                        p[i] = s;
                        break;

                    case "System.Int32":
                        if (s.StartsWith("0x"))
                        {
                            p[i] = Int32.Parse(s.Substring(2), NumberStyles.HexNumber);
                        }
                        else
                        {
                            p[i] = Int32.Parse(s, NumberStyles.Any);
                        }
                        break;

                    case "System.Int16":
                        if (s.StartsWith("0x"))
                        {
                            p[i] = Int16.Parse(s.Substring(2), NumberStyles.HexNumber);
                        }
                        else
                        {
                            p[i] = Int16.Parse(s, NumberStyles.Any);
                        }
                        break;

                    case "System.Int64":
                        if (s.StartsWith("0x"))
                        {
                            p[i] = Int64.Parse(s.Substring(2), NumberStyles.HexNumber);
                        }
                        else
                        {
                            p[i] = Int64.Parse(s, NumberStyles.Any);
                        }
                        break;

                    case "System.UInt32":
                        if (s.StartsWith("0x"))
                        {
                            p[i] = UInt32.Parse(s.Substring(2), NumberStyles.HexNumber);
                        }
                        else
                        {
                            p[i] = UInt32.Parse(s, NumberStyles.Any);
                        }
                        break;

                    case "System.UInt16":
                        if (s.StartsWith("0x"))
                        {
                            p[i] = UInt16.Parse(s.Substring(2), NumberStyles.HexNumber);
                        }
                        else
                        {
                            p[i] = UInt16.Parse(s, NumberStyles.Any);
                        }
                        break;

                    case "System.UInt64":
                        if (s.StartsWith("0x"))
                        {
                            p[i] = UInt64.Parse(s.Substring(2), NumberStyles.HexNumber);
                        }
                        else
                        {
                            p[i] = UInt64.Parse(s, NumberStyles.Any);
                        }
                        break;

                    case "System.Decimal":
                        if (s.StartsWith("0x"))
                        {
                            p[i] = Decimal.Parse(s.Substring(2), NumberStyles.HexNumber);
                        }
                        else
                        {
                            p[i] = Decimal.Parse(s, NumberStyles.Any);
                        }
                        break;

                    case "System.Double":
                        if (s.StartsWith("0x"))
                        {
                            p[i] = Double.Parse(s.Substring(2), NumberStyles.HexNumber);
                        }
                        else
                        {
                            p[i] = Double.Parse(s, NumberStyles.Any);
                        }
                        break;

                    case "System.Byte":
                        p[i] = Convert.ToByte(s);
                        break;

                    case "System.SByte":
                        p[i] = Convert.ToSByte(s);
                        break;

                    case "System.Boolean":
                        p[i] = Convert.ToBoolean(s);
                        break;

                    case "System.Char":
                        p[i] = Convert.ToChar(s);
                        break;

                    case "System.DateTime":
                        p[i] = DateTime.Parse(s);
                        break;

                    case "System.Byte[]":
                        string[] byteStrs = s.Replace(" ", "").Replace("\r", "").Replace("\n", "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        byte[]   bytes    = new byte[byteStrs.Length];
                        for (int j = 0; j < bytes.Length; j++)
                        {
                            string tmpStr = byteStrs[j];
                            if (tmpStr.StartsWith("0x"))
                            {
                                bytes[j] = Byte.Parse(tmpStr.Substring(2), NumberStyles.HexNumber);
                            }
                            else
                            {
                                bytes[j] = Byte.Parse(tmpStr, NumberStyles.Any);
                            }
                        }
                        p[i] = bytes;
                        break;

                    default:
                        p[i] = s;
                        break;
                    }
                }


                SimpleTextbox.AppendText(txtInfo, String.Format("=== Started at {0} ===\r\n", DateTime.Now));

                object o = mb.Invoke(null, p);
                if (o != null)
                {
                    SimpleTextbox.AppendText(txtInfo, String.Format("Return Value: {0}\r\n", o));
                    ParameterInfo[] pi = mb.GetParameters();
                    for (int i = 0; i < pi.Length; i++)
                    {
                        if (pi[i].IsOut || pi[i].ParameterType.IsByRef)
                        {
                            SimpleTextbox.AppendText(txtInfo, String.Format("{0}: {1}\r\n", pi[i].Name, p[i]));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SimpleMessage.ShowException(ex);
            }
            finally
            {
                Utils.EnableUI(this.Controls, true);
                if (resolveDirAdded)
                {
                    _host.RemoveAssemblyResolveDir(_sourceDir);
                }
                SimpleTextbox.AppendText(txtInfo, String.Format("=== Completed at {0} ===\r\n\r\n", DateTime.Now));
            }

            //this.Close();
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (cboOpCode.SelectedItem == null)
            {
                SimpleMessage.ShowInfo("Please select proper OpCode.");
                return;
            }

            try
            {
                OpCode op = (OpCode)cboOpCode.SelectedItem;

                switch (op.OperandType)
                {
                case OperandType.InlineBrTarget:
                case OperandType.ShortInlineBrTarget:
                    _ins.OpCode  = op;
                    _ins.Operand = _method.Body.Instructions[cboOperand.SelectedIndex];
                    break;

                case OperandType.InlineString:
                    _ins.OpCode  = op;
                    _ins.Operand = cboOperand.Text;
                    break;

                case OperandType.InlineNone:
                    _ins.OpCode  = op;
                    _ins.Operand = null;
                    break;

                case OperandType.InlineI:
                    _ins.OpCode  = op;
                    _ins.Operand = SimpleParse.ParseInt(cboOperand.Text);
                    break;

                case OperandType.ShortInlineI:
                    _ins.OpCode = op;
                    if (op.Code == Code.Ldc_I4_S)
                    {
                        _ins.Operand = SimpleParse.ParseSByte(cboOperand.Text);
                    }
                    else
                    {
                        _ins.Operand = SimpleParse.ParseByte(cboOperand.Text);
                    }
                    break;

                case OperandType.InlineR:
                    _ins.OpCode  = op;
                    _ins.Operand = Double.Parse(cboOperand.Text);
                    break;

                case OperandType.ShortInlineR:
                    _ins.OpCode  = op;
                    _ins.Operand = Single.Parse(cboOperand.Text);
                    break;

                case OperandType.InlineI8:
                    _ins.OpCode  = op;
                    _ins.Operand = SimpleParse.ParseLong(cboOperand.Text);
                    break;

                case OperandType.InlineField:
                    _ins.OpCode  = op;
                    _ins.Operand = cboOperand.SelectedItem;
                    break;

                case OperandType.InlineVar:
                case OperandType.ShortInlineVar:
                    _ins.OpCode  = op;
                    _ins.Operand = cboOperand.SelectedItem;
                    break;

                case OperandType.ShortInlineArg:
                case OperandType.InlineArg:
                    _ins.OpCode  = op;
                    _ins.Operand = cboOperand.SelectedItem;
                    break;

                case OperandType.InlineMethod:
                    _ins.OpCode = op;
                    if (cboOperand.SelectedItem is MethodReference)
                    {
                        MethodReference mr = (MethodReference)cboOperand.SelectedItem;
                        if (mr.DeclaringType.Module.FullyQualifiedName != _method.DeclaringType.Module.FullyQualifiedName)
                        {
                            _ins.Operand = _method.DeclaringType.Module.Import(mr);
                        }
                        else
                        {
                            _ins.Operand = mr;
                        }
                    }
                    else
                    {
                        MethodInfo      mi;
                        MethodReference mr;
                        switch (cboOperand.Text)
                        {
                        case METHOD_MESSAGEBOX:
                            mi           = typeof(System.Windows.Forms.MessageBox).GetMethod("Show", new Type[] { typeof(string) });
                            mr           = _method.DeclaringType.Module.Import(mi);
                            _ins.Operand = mr;
                            break;
                        }
                    }
                    break;

                case OperandType.InlineSwitch:
                {
                    string opStr = cboOperand.Text;
                    if (opStr != null)
                    {
                        string[] ops = opStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        if (ops != null && ops.Length > 0)
                        {
                            Instruction[] opIns = new Instruction[ops.Length];
                            for (int i = 0; i < ops.Length; i++)
                            {
                                int opIndex = -1;
                                if (int.TryParse(ops[i], out opIndex))
                                {
                                    if (opIndex >= 0 && opIndex < _method.Body.Instructions.Count)
                                    {
                                        opIns[i] = _method.Body.Instructions[opIndex];
                                    }
                                    else
                                    {
                                        opIndex = -1;
                                    }
                                }
                                if (opIndex == -1)
                                {
                                    throw new Exception("Invalid instruction index" + ops[i]);
                                }
                            }
                            _ins.Operand = null;
                            _ins.Operand = opIns;
                        }
                    }
                }
                break;

                case OperandType.InlineType:
                    _ins.OpCode = op;
                    if (cboOperand.SelectedItem == null)
                    {
                        _ins.Operand = ClassEditHelper.ParseTypeReference(cboOperand.Text, _method.Module);
                    }
                    else
                    {
                        _ins.Operand = ClassEditHelper.ParseTypeReference(cboOperand.SelectedItem, _method.Module);
                    }
                    break;

                default:
                    if (_ins.OpCode.OperandType != op.OperandType)
                    {
                        SimpleMessage.ShowInfo(op.Name + " not implemented");
                        return;
                    }
                    else
                    {
                        _ins.OpCode = op;
                        if (cboOperand.SelectedIndex >= 0)
                        {
                            _ins.Operand = cboOperand.SelectedItem;
                        }
                        else
                        {
                            _ins.Operand = null;
                        }
                    }
                    break;
                }


                switch (_mode)
                {
                case EditModes.Edit:
                    break;

                case EditModes.InsertAfter:
                    _ilp.InsertAfter(_method.Body.Instructions[_insIndex], _ins);
                    break;

                case EditModes.InsertBefore:
                    _ilp.InsertBefore(_method.Body.Instructions[_insIndex], _ins);
                    break;
                }

                InsUtils.ComputeOffsets(_method.Body.Instructions);

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                SimpleMessage.ShowException(ex);
            }
        }