Handlers

A CommandDefinition has either a synchronous or asynchronous handler:

// Synchronous
cmdDef.Handler = (cmd) =>
{
    string path = cmd["path"].GetValue<string>();
    // ...
};

// Asynchronous
cmdDef.AsyncHandler = async (cmd) =>
{
    string path = cmd["path"].GetValue<string>();
    await DoWorkAsync(path);
};

CommandExecutor.Execute() and CommandExecutor.ExecuteAsync() dispatch to the appropriate handler after constraint validation.

Handlers can also be assigned as method references:

// Synchronous
cmdDef.Handler = CopyCommand;

static void CopyCommand(ICommand cmd)
{
    string path = cmd["path"].GetValue<string>();
    // ...
}
// Asynchronous
cmdDef.AsyncHandler = CopyCommandAsync;

static async Task CopyCommandAsync(ICommand cmd)
{
    string path = cmd["path"].GetValue<string>();
    await DoWorkAsync(path);
}