private void InvokeCommand() { int idx = GetSelectedIndex(); var list = m_hostWindow.GetList(); if (idx == -1) { if (!list.HasItems) { return; } idx = 0; } QuickMethod method = m_availableMethods[idx]; String arguments = GetArgumentString(GetQueryText()); String realMethod = "invalid"; try { String[] args = arguments == null?QuickModel.GetArguments(method.MethodDefArgs) : QuickModel.GetArguments(arguments); if (method.GetPluginInterface() != null) { method.GetPluginInterface().Invoke(m_comObject, this); } else if (method.MethodParamRegex == "" || method.MethodParamRegex == "." || args.Length > 0) { //将参数塞进MethodScript中 if (method.MethodScript.Trim()[0] == '!') { //!表示对布尔值进行切换 realMethod = method.MethodScript.Trim().Substring(1); object value = QuickSafeReflection.Invoke(realMethod, m_comObject); if (value is bool) { QuickSafeReflection.Set(realMethod, !(bool)value, m_comObject); } } else if (method.MethodScript.Trim()[0] == '@') { String utilityMethod = null; //如果是@开头,表示调用Utilities中方法来赋值或将返回值传给方法中的{$1} //可能存在!在引号内的风险 if (method.MethodScript.Contains("!")) { utilityMethod = method.MethodScript.Substring(1, method.MethodScript.IndexOf('!') - 1); utilityMethod = ReplaceAruguments(utilityMethod, args); realMethod = method.MethodScript.Substring(method.MethodScript.IndexOf('!') + 1); if (method.MethodScript.Trim()[method.MethodScript.Length - 1] != ')') { QuickSafeReflection.Set(realMethod, QuickSafeReflection.Invoke(utilityMethod, m_utilities), m_comObject); } else { realMethod = ReplaceAruguments(realMethod, (String[])QuickSafeReflection.Invoke(utilityMethod, m_utilities)); QuickSafeReflection.Invoke(realMethod, m_comObject); } } else { utilityMethod = method.MethodScript.Substring(1); realMethod = ReplaceAruguments(utilityMethod, args); QuickSafeReflection.Invoke(realMethod, m_utilities); } } else if (method.MethodScript.Trim()[method.MethodScript.Length - 1] != ')') { //如果不以)结尾,表示是一个赋值方法 realMethod = method.MethodScript; QuickSafeReflection.Set(realMethod, args[0], m_comObject); } else { realMethod = ReplaceAruguments(method.MethodScript, args); QuickSafeReflection.Invoke(realMethod, m_comObject); } } QuickVitality.UpdateVitality("invoke", m_model.ProgramName, realMethod); } catch (Exception ex) { //在此插入异常 QuickVitality.UpdateVitality("error", m_model.ProgramName, "invoking: " + realMethod + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace); } JobDone(); }