public static void ShowUsageForAll() { var cmdTypes = AssemblySearcher .GetCommandClasses() .OrderBy(t => AssemblySearcher.GetCommandName(t)); //foreach type get the names of the parameters and create a printout foreach (var type in cmdTypes) { var cmdName = AssemblySearcher.GetCommandName(type); Console.WriteLine($"{cmdName} command"); var desc = type.GetCustomAttributes(typeof(CommandClassAttribute), false).Cast <CommandClassAttribute>().First().ShortDescription; if (desc?.Length > 0) { Console.WriteLine(desc); } Console.WriteLine($"usage:"); foreach (var method in AssemblySearcher.GetCommandMethods(type)) { var handlerDesc = method.GetCustomAttributes(typeof(CommandHandlerAttribute), false).Cast <CommandHandlerAttribute>().First().ShortDescription; StringBuilder sb = new StringBuilder(); sb.Append(cmdName).Append(" "); foreach (var param in method.GetParameters()) { sb.Append(param.Name).Append(" "); } Console.WriteLine($" {sb,-60} {handlerDesc}"); } Console.WriteLine("\n"); } }
private Type RetrieveTypeForCommand(string command) { var possibleCommandHandlers = AssemblySearcher.GetCommandClasses(command, IgnoreCommandCase); if (possibleCommandHandlers.Count() > 1) { throw new Exception($"More than one class assigned to handle command {command}"); } if (possibleCommandHandlers.Count() < 1) { throw new Exception($"No handler registered for command: {command}"); } return(possibleCommandHandlers.First()); }