示例#1
0
        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
                    });
                }
            }
        }
示例#2
0
        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);
                    }
                }
            }
        }