/// <summary> /// 自动补全命令 /// </summary> public string GetAutoCompltion(string str) { string[] cmds = str.Split(' '); if (cmds.Length < 1) { return(""); } //模块名 if (cmds.Length == 1) { CheatItem it = GetParseCheatItem(cmds[0]); if (it == null) { return(str); } return(it.GetType().Name); } //模块名+方法名 CheatItem item = GetParseCheatItem(cmds[0]); if (item == null) { return(str); } cmds[0] = item.GetType().Name; cmds[1] = item.GetCommandNameList().Find((name) => name.ToLower().StartsWith(cmds[1].ToLower())); if (cmds[1] == null) { return(str); } return(string.Join(" ", cmds)); }
/// <summary> /// 获取指定可以进行自动补全命令的列表 /// </summary> public List <string> GetCommandCompletionList(string str) { string[] cmds = str.Split(' '); if (cmds.Length < 1) { return(null); } //模块名 if (cmds.Length == 1) { return(_cheatItems.FindAll((i) => i.GetType().Name.ToLower().StartsWith(str.Trim().ToLower())).ConvertAll <string>((citem) => citem.GetType().Name)); } CheatItem item = GetParseCheatItem(cmds[0]); string name = item.GetType().Name; List <string> cmdList = new List <string>(); cmdList = item.GetCommandNameList().FindAll((cmdName) => cmdName.ToLower().StartsWith(cmds[1].ToLower())).ConvertAll <string>((rawName) => name + rawName); return(cmdList); }
/// <summary> /// 执行命令 /// </summary> /// <param name="command"></param> /// <returns></returns> public string RunCommand(string command) { if (string.IsNullOrEmpty(command)) { return(ConstLanguage.ErrorNullCommand); } command = command.Trim(); string[] cmds = command.Split(' '); CheatItem item = _cheatItems.Find((i) => i.GetType().Name == cmds[0]); if (item == null) { return(ConstLanguage.Get(ConstLanguage.ErrorNotFindCommand, cmds[0])); } //无参数默认命令 if (cmds.Length == 1) { #region 处理只有一个单位的默认命令 return(RunMethod(item, "DefaultSingleMethod", null)); #endregion } //有一个参数默认命令 if (item.GetCommandNameList().FindIndex((cmdName) => cmdName == cmds[1]) == -1) { object[] vals = new object[cmds.Length - 1]; Array.Copy(cmds, 1, vals, 0, vals.Length); return(RunMethod(item, "DefaultOneParamsMethod", vals)); } string name = cmds[1]; object[] parms = new object[cmds.Length - 2]; Array.Copy(cmds, 2, parms, 0, parms.Length); return(RunMethod(item, name, parms)); }