public void MultiRegister <T>(CommandName commandType, Action <T> execute, Func <T, bool> canExecute) where T : class { ICommand command = new MessengerCommand <T>(execute, canExecute); if (commands.ContainsKey(commandType)) { OnBusinessLogicException(commandType); } else { if (multiCommands.ContainsKey(commandType)) { if (multiCommands[commandType].All(x => !command.Equals(x))) { multiCommands[commandType].Add(command); } } else { multiCommands.Add(commandType, new List <ICommand> { command }); } } }
public void MultiUnregister <T>(CommandName commandType, Action <T> execute, Func <T, bool> canExecute) where T : class { if (commands.ContainsKey(commandType)) { OnBusinessLogicException(commandType); } else { MessengerCommand <T> command = new MessengerCommand <T>(execute, canExecute); if (multiCommands.ContainsKey(commandType) && multiCommands[commandType] != null) { multiCommands[commandType].RemoveAll(x => command.Equals(x)); if (!multiCommands[commandType].Any()) { MultiUnregister(commandType); } } } }