Skip to content

Add a Property in RelayCommandAttribute to allow to set the XXXX part of autogenerated name "XXXXCommand" instead of pick the method name. #1172

@DrkWzrd

Description

@DrkWzrd

Overview

Sometimes we are forced to put a name to a method (for repeated name with other methods) that it is not "ideal" to put as the generated command name. It will be preferrable to be able to set the name of the command manually.

This brings more control to the developer even to name the methods as they want.

API breakdown

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public sealed class RelayCommandAttribute : Attribute
{
    public string? Name { get; init; } //--> If null or whitespace, default behaviour
    public string? CanExecute { get; init; }
    public bool AllowConcurrentExecutions { get; init; }
    public bool FlowExceptionsToTaskScheduler { get; init; }
    public bool IncludeCancelCommand { get; init; }
}

Usage example

[RelayCommand(Name = "SaveProject", CanExecute = nameof(CanSaveProject), IncludeCancelCommand = true)]
private async Task SaveProjectPrivateAsync(T? projectViewModel, CancellationToken cancellationToken = default);
protected virtual bool CanSaveProject(T? projectViewModel);

Breaking change?

No

Alternatives

Nothing.

Additional context

No response

Help us help you

No, just wanted to propose this

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature request 📬A request for new changes to improve functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions