public void AddCommand(Command command, IReadOnlyList <string> segments, int startIndex) { if (segments.Count == 0) { throw new CommandMappingException(command, null, "Cannot map commands without aliases to the root node."); } var segment = segments[startIndex]; if (startIndex == segments.Count - 1) { if (_commands.TryGetValue(segment, out var commands)) { ValidateCommand(command, segment, commands); commands.Add(command); } else { _commands.Add(segment, new List <Command> { command }); } } else { if (!_nodes.TryGetValue(segment, out var node)) { node = new CommandMapNode(_service); _nodes.Add(segment, node); } node.AddCommand(command, segments, startIndex + 1); } }
public CommandMap(CommandService service) { _rootNode = new CommandMapNode(service); }