private int CalculateCommandIndex(ICommandVM cmd, bool forward, out ICommandsCollection coll) { var offset = forward ? 1 : -1; coll = FindCommandCollection(cmd); var index = coll.Commands.IndexOf(cmd); if (index == -1) { throw new IndexOutOfRangeException("Index of the command is not found"); } return(index + offset); }
public static void Wire(ViewModelBase <T> vm, ICommandsCollection collection) { if (_commands == null) { var viewModelType = typeof(T); lock (typeof(CommandCollectionFactory <T>)) { _commands = new List <ICommandFactory <T> >(); var tupleType = typeof(ValueTuple <,>); var methods = viewModelType .GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) .ToArray(); foreach (var m in methods.Where(m => m.ReturnType.IsGenericType && m.ReturnType.GetGenericTypeDefinition() == tupleType)) { var args = m.ReturnType.GetGenericArguments(); var keyType = args[0]; var commandType = args[1]; if (!typeof(ICommand).IsAssignableFrom(commandType)) { throw new InvalidViewModelStructureException($"'{commandType.FullName}' is expected to implement interface ICommand, because it was found in method '{m.Name}' of class '{typeof(T).FullName}'."); } var factoryType = typeof(CommandFactory <, ,>).MakeGenericType(viewModelType, keyType, commandType); var factory = Ctor <ICommandFactory <T> > .Create(factoryType); factory.Configure(m); _commands.Add(factory); } } } foreach (var i in _commands) { var cmd = i.Create((T)vm); collection.Add(i.CommandName, cmd); } }
public HelpCommand(IConsole console, ICommandsCollection commands) : base(console) { _commands = commands; }
public DefaultGenomeBuilder(ICommandsCollection availableCommands, EmulationConfig config, Random random) { this.availableCommands = availableCommands; this.config = config; this.random = random; }
internal AppRunner(IConsole console, ICommandsCollection commands) { _console = console; _commands = commands; }