using GFramework.Core.Abstractions.Command;
using IAsyncCommand = GFramework.Core.Abstractions.Command.IAsyncCommand;
namespace GFramework.Core.Command;
///
/// 表示一个命令执行器,用于执行命令操作。
/// 该类实现了 ICommandExecutor 接口,提供命令执行的核心功能。
///
public sealed class CommandExecutor : ICommandExecutor
{
///
/// 发送并执行无返回值的命令
///
/// 要执行的命令对象,不能为空
/// 当command参数为null时抛出
public void Send(ICommand command)
{
ArgumentNullException.ThrowIfNull(command);
command.Execute();
}
///
/// 发送并执行有返回值的命令
///
/// 命令执行结果的类型
/// 要执行的命令对象,不能为空
/// 命令执行的结果
/// 当command参数为null时抛出
public TResult Send(ICommand command)
{
ArgumentNullException.ThrowIfNull(command);
return command.Execute();
}
///
/// 发送并异步执行无返回值的命令
///
/// 要执行的命令对象,不能为空
/// 当command参数为null时抛出
public Task SendAsync(IAsyncCommand command)
{
ArgumentNullException.ThrowIfNull(command);
return command.ExecuteAsync();
}
///
/// 发送并异步执行有返回值的命令
///
/// 命令执行结果的类型
/// 要执行的命令对象,不能为空
/// 命令执行的结果
/// 当command参数为null时抛出
public Task SendAsync(IAsyncCommand command)
{
ArgumentNullException.ThrowIfNull(command);
return command.ExecuteAsync();
}
}