docs.unity3d.com
    Show / Hide Table of Contents

    Class AsyncRelayCommand<T>

    A generic command that provides a more specific version of AsyncRelayCommand.

    Inheritance
    Object
    AsyncRelayCommand<T>
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.AppUI.MVVM
    Syntax
    public class AsyncRelayCommand<T> : IAsyncRelayCommand<T>, IAsyncRelayCommand, INotifyPropertyChanged, IRelayCommand<T>, IRelayCommand, ICommand
    Type Parameters
    Name Description
    T

    The type of parameter being passed as input to the callbacks.

    Constructors

    AsyncRelayCommand(Func<T, CancellationToken, Task>)

    Initializes a new instance of the AsyncRelayCommand<T> class.

    Declaration
    public AsyncRelayCommand(Func<T, CancellationToken, Task> cancellableExecute)
    Parameters
    Type Name Description
    Func<T, CancellationToken, Task> cancellableExecute

    The Func<T1,T2,TResult> to invoke when the command is executed.

    Exceptions
    Type Condition
    ArgumentNullException

    cancellableExecute is null.

    AsyncRelayCommand(Func<T, CancellationToken, Task>, Predicate<T>)

    Initializes a new instance of the AsyncRelayCommand<T> class.

    Declaration
    public AsyncRelayCommand(Func<T, CancellationToken, Task> cancellableExecute, Predicate<T> canExecute)
    Parameters
    Type Name Description
    Func<T, CancellationToken, Task> cancellableExecute

    The Func<T1,T2,TResult> to invoke when the command is executed.

    Predicate<T> canExecute

    The Predicate<T> to invoke to determine whether the command can execute.

    Exceptions
    Type Condition
    ArgumentNullException

    cancellableExecute or canExecute is null.

    AsyncRelayCommand(Func<T, CancellationToken, Task>, Predicate<T>, AsyncRelayCommandOptions)

    Initializes a new instance of the AsyncRelayCommand<T> class.

    Declaration
    public AsyncRelayCommand(Func<T, CancellationToken, Task> cancellableExecute, Predicate<T> canExecute, AsyncRelayCommandOptions options)
    Parameters
    Type Name Description
    Func<T, CancellationToken, Task> cancellableExecute

    The Func<T1,T2,TResult> to invoke when the command is executed.

    Predicate<T> canExecute

    The Predicate<T> to invoke to determine whether the command can execute.

    AsyncRelayCommandOptions options

    The AsyncRelayCommandOptions to use when executing the command.

    Exceptions
    Type Condition
    ArgumentNullException

    cancellableExecute or canExecute is null.

    AsyncRelayCommand(Func<T, CancellationToken, Task>, AsyncRelayCommandOptions)

    Initializes a new instance of the AsyncRelayCommand<T> class.

    Declaration
    public AsyncRelayCommand(Func<T, CancellationToken, Task> cancellableExecute, AsyncRelayCommandOptions options)
    Parameters
    Type Name Description
    Func<T, CancellationToken, Task> cancellableExecute

    The Func<T1,T2,TResult> to invoke when the command is executed.

    AsyncRelayCommandOptions options

    The AsyncRelayCommandOptions to use when executing the command.

    Exceptions
    Type Condition
    ArgumentNullException

    cancellableExecute is null.

    AsyncRelayCommand(Func<T, Task>)

    Initializes a new instance of the AsyncRelayCommand<T> class.

    Declaration
    public AsyncRelayCommand(Func<T, Task> execute)
    Parameters
    Type Name Description
    Func<T, Task> execute

    The Func<T,TResult> to invoke when the command is executed.

    Exceptions
    Type Condition
    ArgumentNullException

    execute is null.

    AsyncRelayCommand(Func<T, Task>, Predicate<T>)

    Initializes a new instance of the AsyncRelayCommand<T> class.

    Declaration
    public AsyncRelayCommand(Func<T, Task> execute, Predicate<T> canExecute)
    Parameters
    Type Name Description
    Func<T, Task> execute

    The Func<T,TResult> to invoke when the command is executed.

    Predicate<T> canExecute

    The Predicate<T> to invoke to determine whether the command can execute.

    Exceptions
    Type Condition
    ArgumentNullException

    execute or canExecute is null.

    AsyncRelayCommand(Func<T, Task>, Predicate<T>, AsyncRelayCommandOptions)

    Initializes a new instance of the AsyncRelayCommand<T> class.

    Declaration
    public AsyncRelayCommand(Func<T, Task> execute, Predicate<T> canExecute, AsyncRelayCommandOptions options)
    Parameters
    Type Name Description
    Func<T, Task> execute

    The Func<T1,T2,TResult> to invoke when the command is executed.

    Predicate<T> canExecute

    The Predicate<T> to invoke to determine whether the command can execute.

    AsyncRelayCommandOptions options

    The AsyncRelayCommandOptions to use when executing the command.

    Exceptions
    Type Condition
    ArgumentNullException

    execute or canExecute is null.

    AsyncRelayCommand(Func<T, Task>, AsyncRelayCommandOptions)

    Initializes a new instance of the AsyncRelayCommand<T> class.

    Declaration
    public AsyncRelayCommand(Func<T, Task> execute, AsyncRelayCommandOptions options)
    Parameters
    Type Name Description
    Func<T, Task> execute

    The Func<T,TResult> to invoke when the command is executed.

    AsyncRelayCommandOptions options

    The AsyncRelayCommandOptions to use when executing the command.

    Exceptions
    Type Condition
    ArgumentNullException

    execute is null.

    Properties

    canBeCancelled

    Gets a value indicating whether this AsyncRelayCommand<T> can be cancelled.

    Declaration
    public bool canBeCancelled { get; }
    Property Value
    Type Description
    Boolean
    Implements
    IAsyncRelayCommand.canBeCancelled

    executionTask

    Gets a value indicating whether this AsyncRelayCommand<T> is currently running.

    Declaration
    public Task executionTask { get; set; }
    Property Value
    Type Description
    Task
    Implements
    IAsyncRelayCommand.executionTask

    isCancellationRequested

    Gets a value indicating whether this AsyncRelayCommand<T> has been cancelled.

    Declaration
    public bool isCancellationRequested { get; }
    Property Value
    Type Description
    Boolean
    Implements
    IAsyncRelayCommand.isCancellationRequested

    isRunning

    Gets a value indicating whether this AsyncRelayCommand<T> is currently running.

    Declaration
    public bool isRunning { get; }
    Property Value
    Type Description
    Boolean
    Implements
    IAsyncRelayCommand.isRunning

    Methods

    Cancel()

    Cancels the current execution of this AsyncRelayCommand<T>.

    Declaration
    public void Cancel()
    Implements
    IAsyncRelayCommand.Cancel()

    CanExecute(T)

    Determines whether this AsyncRelayCommand<T> can execute in its current state.

    Declaration
    public bool CanExecute(T parameter)
    Parameters
    Type Name Description
    T parameter

    The parameter to use when determining whether the command can execute.

    Returns
    Type Description
    Boolean

    True if this command can be executed; otherwise, false.

    Implements
    IRelayCommand<T>.CanExecute(T)

    CanExecute(Object)

    Determines whether this AsyncRelayCommand<T> can execute in its current state.

    Declaration
    public bool CanExecute(object parameter)
    Parameters
    Type Name Description
    Object parameter

    The parameter to use when determining whether the command can execute.

    Returns
    Type Description
    Boolean

    True if this command can be executed; otherwise, false.

    Implements
    ICommand.CanExecute(Object)
    Exceptions
    Type Condition
    InvalidOperationException

    ExecuteAsync(T) has not been called.

    Execute(T)

    Executes the AsyncRelayCommand<T> synchronously on the current thread.

    Declaration
    public void Execute(T parameter)
    Parameters
    Type Name Description
    T parameter

    The parameter to use when executing the command.

    Implements
    IRelayCommand<T>.Execute(T)

    Execute(Object)

    Determines whether this AsyncRelayCommand<T> can execute in its current state.

    Declaration
    public void Execute(object parameter)
    Parameters
    Type Name Description
    Object parameter

    The parameter to use when determining whether the command can execute.

    Implements
    ICommand.Execute(Object)
    Exceptions
    Type Condition
    InvalidOperationException

    ExecuteAsync(T) has not been called.

    ExecuteAsync(T)

    Occurs when changes occur that affect whether the command should execute.

    Declaration
    public Task ExecuteAsync(T parameter)
    Parameters
    Type Name Description
    T parameter

    The parameter to use when determining whether the command can execute.

    Returns
    Type Description
    Task

    True if this command can be executed; otherwise, false.

    Implements
    IAsyncRelayCommand<T>.ExecuteAsync(T)

    ExecuteAsync(Object)

    Gets a value indicating whether this AsyncRelayCommand<T> can be executed.

    Declaration
    public Task ExecuteAsync(object parameter)
    Parameters
    Type Name Description
    Object parameter

    The parameter to use when determining whether the command can execute.

    Returns
    Type Description
    Task

    True if this command can be executed; otherwise, false.

    Implements
    IAsyncRelayCommand.ExecuteAsync(Object)
    Exceptions
    Type Condition
    InvalidOperationException

    ExecuteAsync(T) has not been called.

    NotifyCanExecuteChanged()

    Raises CanExecuteChanged.

    Declaration
    public void NotifyCanExecuteChanged()
    Implements
    IRelayCommand.NotifyCanExecuteChanged()

    Events

    CanExecuteChanged

    Event raised when the CanExecute(Object) property changes.

    Declaration
    public event EventHandler CanExecuteChanged
    Event Type
    Type Description
    EventHandler
    Implements
    ICommand.CanExecuteChanged

    PropertyChanged

    Event raised when the executionTask property changes.

    Declaration
    public event PropertyChangedEventHandler PropertyChanged
    Event Type
    Type Description
    PropertyChangedEventHandler
    Implements
    INotifyPropertyChanged.PropertyChanged
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023