RunicCommandKeyAttribute class

Namespace Runic.Application.Views in Runic.Application.Views 0.23.0

public sealed class RunicCommandKeyAttribute : Attribute

Inherits or implements Attribute.

Resolves a command's parameter from a wire key: the generated client sends the key, and the Bridge calls the named ViewModel method to get the parameter. null means "no such object": the call is rejected with the reason unresolved-key and the command does not run.

Remarks

Put it on the command property or on a CommunityToolkit [RelayCommand] method. RunicCommandKeyAttribute.Resolver names one method of the ViewModel that is not overloaded, instance or static, public or internal, with one of these shapes, where TKey is any supported command input type and P the command's parameter type:

P? Find(TKey key)
ValueTask<P?> FindAsync(TKey key)                                       // also Task<P?>
ValueTask<P?> FindAsync(TKey key, CancellationToken cancellationToken)  // also Task<P?>

A synchronous resolver runs in the Bridge call's model turn. An asynchronous one starts in that turn; the command's availability and execution then run in a new turn with the resolved object. CanExecute sees the resolved object. A resolver must be free of side effects: it can run more than once for one request, for example for can… and then the command, or for a repeated operation start. A plain ICommand takes this attribute instead of RunicCommandInputAttribute.

Constructors

RunicCommandKeyAttribute

public RunicCommandKeyAttribute(string resolver)

Resolves a command's parameter from a wire key: the generated client sends the key, and the Bridge calls the named ViewModel method to get the parameter. null means "no such object": the call is rejected with the reason unresolved-key and the command does not run.

Remarks

Put it on the command property or on a CommunityToolkit [RelayCommand] method. RunicCommandKeyAttribute.Resolver names one method of the ViewModel that is not overloaded, instance or static, public or internal, with one of these shapes, where TKey is any supported command input type and P the command's parameter type:

P? Find(TKey key)
ValueTask<P?> FindAsync(TKey key)                                       // also Task<P?>
ValueTask<P?> FindAsync(TKey key, CancellationToken cancellationToken)  // also Task<P?>

A synchronous resolver runs in the Bridge call's model turn. An asynchronous one starts in that turn; the command's availability and execution then run in a new turn with the resolved object. CanExecute sees the resolved object. A resolver must be free of side effects: it can run more than once for one request, for example for can… and then the command, or for a repeated operation start. A plain ICommand takes this attribute instead of RunicCommandInputAttribute.

Properties

Resolver

public string Resolver { get; }

The name of the ViewModel method that resolves the key, such as nameof(FindItem).