private string RunMethod(CheatItem item, string name, object[] parms) { try { //获取模块信息 MethodInfo met = item.GetType().GetMethod(name); CommandInfo info = GetCommandInfo(met); if (info != null && !info.CanExecute) { return(ConstLanguage.Get(ConstLanguage.ErrorCommandPolicy, info.RequireLevelName)); } ParameterInfo[] paramsInfo = met.GetParameters(); if (parms != null) { if (parms.Length != paramsInfo.Length) { Array.Resize <object>(ref parms, paramsInfo.Length); } for (int i = 0; i < paramsInfo.Length; i++) { if (parms[i] != null) { parms[i] = Convert.ChangeType(parms[i], paramsInfo[i].ParameterType); } else { parms[i] = paramsInfo[i].DefaultValue; } } } object res = met.Invoke(item, parms); return(res == null ? "" : ConstLanguage.Get(ConstLanguage.CommandResult, res.ToString())); } catch (Exception ex) { string cmdList = item.GetCommandDescList(); if (string.IsNullOrEmpty(cmdList)) { return(ConstLanguage.Get(ConstLanguage.ErrorCommand, ex.Message)); } return(ConstLanguage.Get(ConstLanguage.ErrorCommandParams, ex.Message, cmdList)); } }
/// <summary> /// 获取指定命令的帮助信息 /// </summary> public string GetTargetCommandHelp(string cmdName) { CheatItem item = _cheatItems.Find((i) => i.GetType().Name == cmdName); if (item == null) { return(ConstLanguage.Get(ConstLanguage.ErrorNotFindCommand, cmdName)); } CommandInfo expl = (CommandInfo)System.Attribute.GetCustomAttribute(item.GetType(), typeof(CommandInfo)); return(ConstLanguage.Get("{0}>>>>>{1}\n\n{2}", string.IsNullOrEmpty(expl.Name) ? item.GetType().Name : expl.Name, expl.Explain, item.GetCommandDescList())); }