25 lines
665 B
C#
25 lines
665 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Questionable.Controller.DebugCommands;
|
|
|
|
internal sealed class DebugCommandExecutor
|
|
{
|
|
private readonly Dictionary<string, IDebugCommandHandler> _handlers;
|
|
|
|
public DebugCommandExecutor(IEnumerable<IDebugCommandHandler> handlers)
|
|
{
|
|
_handlers = handlers.ToDictionary<IDebugCommandHandler, string>((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;
|
|
}
|
|
}
|