public Command(MethodInfo aMethod, string alias, string hint) { method = aMethod; name = !string.IsNullOrEmpty(alias) ? alias : method.Name; this.hint = hint; parms = ConsoleParam.GenerateParams(method); }
public void Execute(string line) { if (string.IsNullOrEmpty(line)) { return; } string commandName; string parmLine = ""; //grab first word int spaceInd = line.IndexOf(' '); if (spaceInd != -1) { commandName = line.Substring(0, spaceInd); if (spaceInd < line.Length - 1) { parmLine = line.Substring(spaceInd + 1, line.Length - spaceInd - 1); } } else { commandName = line; } var command = GetCommand(commandName); if (command != null) { if (string.IsNullOrEmpty(parmLine) && command.parms.Length > 0) { Log(command.logHint); } else { object[] objParms; if (ConsoleParam.Parse(command.parms, parmLine, out objParms)) { command.Execute(objParms); } else { Log(LogType.Log, tagCommand, command.logHint); } } } else { Log(LogType.Log, tagCommand, "Unknown Command: " + commandName); } }
public Command(MethodInfo aMethod) { method = aMethod; var commandAttr = System.Attribute.GetCustomAttribute(method, typeof(ConsoleCommandAttribute), true) as ConsoleCommandAttribute; if (commandAttr != null) { name = !string.IsNullOrEmpty(commandAttr.alias) ? commandAttr.alias : method.Name; hint = commandAttr.hint; } else { name = method.Name; hint = ""; } parms = ConsoleParam.GenerateParams(method); }