diff --git a/src/Prism.Core/Commands/CompositeCommand.cs b/src/Prism.Core/Commands/CompositeCommand.cs index 5ccb5fce0..268cef2d1 100644 --- a/src/Prism.Core/Commands/CompositeCommand.cs +++ b/src/Prism.Core/Commands/CompositeCommand.cs @@ -11,6 +11,19 @@ namespace Prism.Commands /// /// The CompositeCommand composes one or more ICommands. /// + /// + /// + /// allows you to register multiple commands and execute them all with a single call. + /// This is useful for scenarios where an action should trigger multiple operations across different parts of an application. + /// + /// + /// The composite command can optionally monitor the activity of its registered commands if they implement . + /// When monitoring is enabled, the composite command will only execute commands that are active. + /// + /// + /// The method returns only if all registered commands can execute. + /// + /// public class CompositeCommand : ICommand { private readonly List _registeredCommands = new(); @@ -21,6 +34,9 @@ public class CompositeCommand : ICommand /// /// Initializes a new instance of . /// + /// + /// By default, the composite command will not monitor the activity of registered commands. + /// public CompositeCommand() { _onRegisteredCommandCanExecuteChangedHandler = new EventHandler(OnRegisteredCommandCanExecuteChanged); @@ -30,7 +46,11 @@ public CompositeCommand() /// /// Initializes a new instance of . /// - /// Indicates when the command activity is going to be monitored. + /// Indicates when the command activity is going to be monitored. + /// When , the composite command will only execute registered commands that are active (if they implement ). + /// + /// When activity monitoring is enabled, only commands that are active will be executed. + /// public CompositeCommand(bool monitorCommandActivity) : this() { @@ -41,11 +61,19 @@ public CompositeCommand(bool monitorCommandActivity) /// Adds a command to the collection and signs up for the event of it. /// /// + /// /// If this command is set to monitor command activity, and /// implements the interface, this method will subscribe to its /// event. + /// + /// + /// The same command cannot be registered twice, and a composite command cannot be registered within itself. + /// /// /// The command to register. + /// Thrown when is . + /// Thrown when attempting to register a composite command within itself. + /// Thrown when the same command is registered twice. public virtual void RegisterCommand(ICommand command) { if (command == null) throw new ArgumentNullException(nameof(command)); @@ -79,6 +107,7 @@ public virtual void RegisterCommand(ICommand command) /// Removes a command from the collection and removes itself from the event of it. /// /// The command to unregister. + /// Thrown when is . public virtual void UnregisterCommand(ICommand command) { if (command == null) throw new ArgumentNullException(nameof(command)); diff --git a/src/Prism.Core/Commands/DelegateCommand.cs b/src/Prism.Core/Commands/DelegateCommand.cs index cd98aac21..7ee65628a 100644 --- a/src/Prism.Core/Commands/DelegateCommand.cs +++ b/src/Prism.Core/Commands/DelegateCommand.cs @@ -10,8 +10,19 @@ namespace Prism.Commands /// /// An whose delegates do not take any parameters for and . /// - /// - /// + /// + /// + /// is a command implementation that allows you to define the execute and canExecute logic + /// using delegates. Unlike UI-based commands, DelegateCommand does not accept parameters. + /// + /// + /// DelegateCommand supports fluent syntax through methods like , + /// , and to make creating + /// and configuring commands easier. + /// + /// + /// + /// public class DelegateCommand : DelegateCommandBase { Action _executeMethod; @@ -21,6 +32,7 @@ public class DelegateCommand : DelegateCommandBase /// Creates a new instance of with the to invoke on execution. /// /// The to invoke when is called. + /// Thrown when is . public DelegateCommand(Action executeMethod) : this(executeMethod, () => true) { @@ -33,6 +45,10 @@ public DelegateCommand(Action executeMethod) /// /// The to invoke when is called. /// The to invoke when is called + /// Thrown when or is . + /// + /// Both delegates must be non-null. If either is null, an will be thrown. + /// public DelegateCommand(Action executeMethod, Func canExecuteMethod) : base() { @@ -46,6 +62,10 @@ public DelegateCommand(Action executeMethod, Func canExecuteMethod) /// /// Executes the command. /// + /// + /// Calls the delegate registered during construction. If an exception occurs and has been registered + /// with , it will be handled; otherwise, the exception is rethrown. + /// public void Execute() { try @@ -65,6 +85,9 @@ public void Execute() /// Determines if the command can be executed. /// /// Returns if the command can execute,otherwise returns . + /// + /// Calls the canExecute delegate registered during construction. If an exception occurs, it will return . + /// public bool CanExecute() { try @@ -94,7 +117,7 @@ protected override void Execute(object? parameter) /// /// Handle the internal invocation of /// - /// + /// Command Parameter (ignored by this implementation) /// if the Command Can Execute, otherwise protected override bool CanExecute(object? parameter) { @@ -107,6 +130,9 @@ protected override bool CanExecute(object? parameter) /// The object type containing the property specified in the expression. /// The property expression. Example: ObservesProperty(() => PropertyName). /// The current instance of DelegateCommand + /// + /// This method enables automatic notification of command execution state changes when observed properties change. + /// public DelegateCommand ObservesProperty(Expression> propertyExpression) { ObservesPropertyInternal(propertyExpression); @@ -118,6 +144,10 @@ public DelegateCommand ObservesProperty(Expression> propertyExpressio /// /// The property expression. Example: ObservesCanExecute(() => PropertyName). /// The current instance of DelegateCommand + /// + /// This method replaces the canExecute delegate provided during construction with the compiled expression, + /// and automatically raises CanExecuteChanged when the observed property changes. + /// public DelegateCommand ObservesCanExecute(Expression> canExecuteExpression) { _canExecuteMethod = canExecuteExpression.Compile(); @@ -130,6 +160,9 @@ public DelegateCommand ObservesCanExecute(Expression> canExecuteExpre /// /// The Callback /// The current instance of + /// + /// The exception handler will be invoked only for exceptions of type . + /// public DelegateCommand Catch(Action @catch) { ExceptionHandler.Register(@catch); @@ -141,6 +174,9 @@ public DelegateCommand Catch(Action @catch) /// /// The Callback /// The current instance of + /// + /// The exception handler will be invoked with both the exception and the command parameter. + /// public DelegateCommand Catch(Action @catch) { ExceptionHandler.Register(@catch);