Catel.MVVM.CommandManager.CreateCommand C# (CSharp) Метод

CreateCommand() публичный Метод

Creates the command inside the command manager.
The is null or whitespace. The specified command is already created using the method.
public CreateCommand ( string commandName, ICompositeCommand compositeCommand = null, bool throwExceptionWhenCommandIsAlreadyCreated = true ) : void
commandName string Name of the command.
compositeCommand ICompositeCommand The composite command. If null, this will default to a new instance of .
throwExceptionWhenCommandIsAlreadyCreated bool if set to true, this method will throw an exception when the command is already created.
Результат void
        public void CreateCommand(string commandName, ICompositeCommand compositeCommand = null,
            bool throwExceptionWhenCommandIsAlreadyCreated = true)
        {
            Argument.IsNotNullOrWhitespace("commandName", commandName);

            lock (_lockObject)
            {
                Log.Debug("Creating command '{0}'", commandName);

                if (_commands.ContainsKey(commandName))
                {
                    var error = string.Format("Command '{0}' is already created using the CreateCommand method", commandName);
                    Log.Error(error);

                    if (throwExceptionWhenCommandIsAlreadyCreated)
                    {
                        throw new InvalidOperationException(error);
                    }

                    return;
                }

                if (compositeCommand == null)
                {
                    compositeCommand = new CompositeCommand();
                }

                _commands.Add(commandName, compositeCommand);

                InvalidateCommands();

                CommandCreated.SafeInvoke(this, () => new CommandCreatedEventArgs(compositeCommand, commandName));
            }
        }
#endif

Same methods

CommandManager::CreateCommand ( string commandName, Catel.Windows.Input.InputGesture inputGesture = null, ICompositeCommand compositeCommand = null, bool throwExceptionWhenCommandIsAlreadyCreated = true ) : void

Usage Example

Пример #1
0
            public void ThrowsInvalidOperationExceptionForAlreadyCreatedCommand()
            {
                var commandManager = new CommandManager();

                commandManager.CreateCommand("MyCommand");

                ExceptionTester.CallMethodAndExpectException<InvalidOperationException>(() => commandManager.CreateCommand("MyCommand"));
            }
All Usage Examples Of Catel.MVVM.CommandManager::CreateCommand