Open sandboxFocus

Class CommandAttribute

Aspect that generates a WPF command property from a method. When applied to a method, it introduces an ICommand property that invokes the method when executed. The aspect supports synchronous commands, asynchronous commands (returning Task), and background commands.

Inheritance
CommandAttribute
Namespace: Metalama.Patterns.Wpf
Assembly: Metalama.Patterns.Wpf.dll
Syntax
[AttributeUsage(AttributeTargets.Method)]
public sealed class CommandAttribute : Attribute, IAspect<IMethod>, IAspect, ICompileTimeSerializable, ITemplateProvider, IEligible<IMethod>
Remarks

The target method becomes the implementation of Execute(object). It must have one of the following signatures: void Execute(), void Execute(T), Task ExecuteAsync(), Task ExecuteAsync(T), or variants with a CancellationToken parameter.

An optional CanExecute property or method can be associated with the command to control when it can be executed. The association can be implicit (based on naming conventions like CanFoo, CanExecuteFoo, or IsFooEnabled) or explicit (via CanExecuteMethod or CanExecuteProperty).

When the containing type implements INotifyPropertyChanged and a CanExecute property is used, the CanExecuteChanged event is automatically raised when the property changes.

Constructors

Name Description
CommandAttribute()

Properties

Name Description
Background

Gets or sets a value indicating whether the command will execute in a background thread. The default value is false, meaning that the command will be executed in the UI thread. If this property is set to true, a property of type AsyncDelegateCommand is generated, even for non-Task execution methods.

CanExecuteMethod

Gets or sets the name of the method that is called to determine whether the command can be executed. This method corresponds to the CanExecute(object) method.

CanExecuteProperty

Gets or sets the name of the property that is evaluated to determine whether the command can be executed. This property corresponds to the CanExecute(object) method.

CommandPropertyName

Gets or sets the name of the ICommand property that is introduced.

EnableINotifyPropertyChangedIntegration

Gets or sets a value indicating whether integration with INotifyPropertyChanged is enabled. The default is true.

SupportsConcurrentExecution

Gets or sets a value indicating whether several executions of the command can run concurrently. This property is only considered for asynchronous methods. Its default value is false, which means that the CanExecute(object) method will return false if another execution is still running. This property is ignored if the execution method is non-Task and the Background property is left to false.

Extension Methods

See Also