From 18267e7c14d4288c08493ea048e211197cf48bce Mon Sep 17 00:00:00 2001 From: GwWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Sun, 4 Jan 2026 22:10:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(command):=20=E4=B8=BA=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E5=92=8C=E6=9F=A5=E8=AF=A2=E7=B1=BB=E6=B7=BB=E5=8A=A0=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E5=8F=82=E6=95=B0=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重构 AbstractCommand 类,添加泛型参数 TInput 并要求实现 ICommandInput 接口 - 修改 AbstractCommand.Execute 方法,传入输入参数到 OnExecute 方法 - 重构 AbstractCommand 类,支持输入参数和返回结果 - 更新 AbstractQuery 类,添加泛型参数 TInput 和 TResult 并要求实现 IQueryInput 接口 - 创建 ICommandInput 接口作为命令输入的标记接口 - 创建 IQueryInput 接口定义查询输入规范 - 为所有抽象方法添加参数文档注释 --- .../command/ICommandInput.cs | 7 ++++ .../query/IQueryInput.cs | 6 ++++ GFramework.Core/command/AbstractCommand.cs | 32 ++++++++++++------- GFramework.Core/query/AbstractQuery.cs | 19 ++++++----- 4 files changed, 44 insertions(+), 20 deletions(-) create mode 100644 GFramework.Core.Abstractions/command/ICommandInput.cs create mode 100644 GFramework.Core.Abstractions/query/IQueryInput.cs diff --git a/GFramework.Core.Abstractions/command/ICommandInput.cs b/GFramework.Core.Abstractions/command/ICommandInput.cs new file mode 100644 index 0000000..57e68d7 --- /dev/null +++ b/GFramework.Core.Abstractions/command/ICommandInput.cs @@ -0,0 +1,7 @@ +namespace GFramework.Core.Abstractions.command; + +/// +/// 命令输入接口,定义命令模式中输入数据的契约 +/// 该接口作为标记接口使用,不包含任何成员定义 +/// +public interface ICommandInput; \ No newline at end of file diff --git a/GFramework.Core.Abstractions/query/IQueryInput.cs b/GFramework.Core.Abstractions/query/IQueryInput.cs new file mode 100644 index 0000000..1a1933d --- /dev/null +++ b/GFramework.Core.Abstractions/query/IQueryInput.cs @@ -0,0 +1,6 @@ +namespace GFramework.Core.Abstractions.query; + +/// +/// 查询输入接口,定义了查询操作的输入规范 +/// +public interface IQueryInput; \ No newline at end of file diff --git a/GFramework.Core/command/AbstractCommand.cs b/GFramework.Core/command/AbstractCommand.cs index aef9baf..a5fa48b 100644 --- a/GFramework.Core/command/AbstractCommand.cs +++ b/GFramework.Core/command/AbstractCommand.cs @@ -6,40 +6,48 @@ namespace GFramework.Core.command; /// /// 抽象命令类,实现 ICommand 接口,为具体命令提供基础架构支持 /// -public abstract class AbstractCommand : ContextAwareBase, ICommand +/// 命令输入参数类型,必须实现 ICommandInput 接口 +/// 命令执行所需的输入参数 +public abstract class AbstractCommand(TInput input) : ContextAwareBase, ICommand + where TInput : ICommandInput { /// - /// 执行命令,调用抽象方法 OnExecute 来实现具体逻辑 + /// 执行命令的入口方法,实现 ICommand 接口的 Execute 方法 /// void ICommand.Execute() { - OnExecute(); + OnExecute(input); } /// - /// 抽象方法,由子类实现具体的命令执行逻辑 + /// 命令执行的抽象方法,由派生类实现具体的命令逻辑 /// - protected abstract void OnExecute(); + /// 命令执行所需的输入参数 + protected abstract void OnExecute(TInput input); } /// /// 带返回值的抽象命令类,实现 ICommand{TResult} 接口,为需要返回结果的命令提供基础架构支持 /// +/// 命令输入参数类型,必须实现 ICommandInput 接口 /// 命令执行后返回的结果类型 -public abstract class AbstractCommand : ContextAwareBase, ICommand +/// 命令执行所需的输入参数 +public abstract class AbstractCommand(TInput input) : ContextAwareBase, ICommand + where TInput : ICommandInput { /// - /// 执行命令,调用抽象方法 OnExecute 来实现具体逻辑并返回结果 + /// 执行命令的入口方法,实现 ICommand{TResult} 接口的 Execute 方法 /// - /// TResult 类型的执行结果 + /// 命令执行后的结果 TResult ICommand.Execute() { - return OnExecute(); + return OnExecute(input); } /// - /// 抽象方法,由子类实现具体的命令执行逻辑 + /// 命令执行的抽象方法,由派生类实现具体的命令逻辑 /// - /// TResult 类型的执行结果 - protected abstract TResult OnExecute(); + /// 命令执行所需的输入参数 + /// 命令执行后的结果 + protected abstract TResult OnExecute(TInput input); } \ No newline at end of file diff --git a/GFramework.Core/query/AbstractQuery.cs b/GFramework.Core/query/AbstractQuery.cs index fbbc1fe..fba9bba 100644 --- a/GFramework.Core/query/AbstractQuery.cs +++ b/GFramework.Core/query/AbstractQuery.cs @@ -6,21 +6,24 @@ namespace GFramework.Core.query; /// /// 抽象查询类,提供查询操作的基础实现 /// -/// 查询结果的类型 -public abstract class AbstractQuery : ContextAwareBase, IQuery +/// 查询输入参数的类型,必须实现IQueryInput接口 +/// 查询结果的类型 +public abstract class AbstractQuery(TInput input) : ContextAwareBase, IQuery + where TInput : IQueryInput { /// /// 执行查询操作 /// - /// 查询结果 - public T Do() + /// 查询结果,类型为TResult + public TResult Do() { - return OnDo(); + return OnDo(input); } /// - /// 抽象方法,由子类实现具体的查询逻辑 + /// 抽象方法,用于实现具体的查询逻辑 /// - /// 查询结果 - protected abstract T OnDo(); + /// 查询输入参数 + /// 查询结果,类型为TResult + protected abstract TResult OnDo(TInput input); } \ No newline at end of file