using System; using System.Collections.Generic; using System.Linq; namespace Questionable.Controller.DebugCommands; internal sealed class DebugCommandExecutor { private readonly Dictionary _handlers; public DebugCommandExecutor(IEnumerable handlers) { _handlers = handlers.ToDictionary((IDebugCommandHandler h) => h.CommandName, StringComparer.OrdinalIgnoreCase); } public bool TryExecute(string command, string[] arguments) { if (_handlers.TryGetValue(command, out IDebugCommandHandler value)) { value.Execute(arguments); return true; } return false; } }