From e29b6da9e1a0ea950f54b7eea167ba431770b7b8 Mon Sep 17 00:00:00 2001
From: GeWuYou <95328647+GeWuYou@users.noreply.github.com>
Date: Sat, 17 Jan 2026 19:26:13 +0800
Subject: [PATCH] =?UTF-8?q?refactor(ContextAwareExtensions):=20=E9=87=8D?=
=?UTF-8?q?=E6=9E=84=E5=91=BD=E4=BB=A4=E5=8F=91=E9=80=81=E6=96=B9=E6=B3=95?=
=?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 移除重复的SendCommand同步方法实现
- 统一Context变量命名规范,修复大小写不一致问题
- 调整方法顺序并重新组织代码结构
- 完善IAsyncCommand接口的XML文档注释
- 优化异步命令执行的实现逻辑
---
.../command/IAsyncCommand.cs | 15 ++++
.../extensions/ContextAwareExtensions.cs | 89 ++++++++-----------
2 files changed, 52 insertions(+), 52 deletions(-)
diff --git a/GFramework.Core.Abstractions/command/IAsyncCommand.cs b/GFramework.Core.Abstractions/command/IAsyncCommand.cs
index 72366bb..a6ae752 100644
--- a/GFramework.Core.Abstractions/command/IAsyncCommand.cs
+++ b/GFramework.Core.Abstractions/command/IAsyncCommand.cs
@@ -3,12 +3,27 @@ using GFramework.Core.Abstractions.rule;
namespace GFramework.Core.Abstractions.command;
+///
+/// 表示一个异步命令接口,该命令不返回结果
+///
public interface IAsyncCommand : IContextAware
{
+ ///
+ /// 异步执行命令
+ ///
+ /// 表示异步操作的任务
Task ExecuteAsync();
}
+///
+/// 表示一个异步命令接口,该命令返回指定类型的结果
+///
+/// 命令执行结果的类型
public interface IAsyncCommand : IContextAware
{
+ ///
+ /// 异步执行命令并返回结果
+ ///
+ /// 表示异步操作的任务,任务结果为命令执行的返回值
Task ExecuteAsync();
}
\ No newline at end of file
diff --git a/GFramework.Core/extensions/ContextAwareExtensions.cs b/GFramework.Core/extensions/ContextAwareExtensions.cs
index 485835d..d21a11a 100644
--- a/GFramework.Core/extensions/ContextAwareExtensions.cs
+++ b/GFramework.Core/extensions/ContextAwareExtensions.cs
@@ -73,38 +73,6 @@ public static class ContextAwareExtensions
return context.SendQuery(query);
}
- ///
- /// 发送一个无返回结果的命令
- ///
- /// 实现 IContextAware 接口的对象
- /// 要发送的命令
- /// 当 contextAware 或 command 为 null 时抛出
- public static void SendCommand(this IContextAware contextAware, ICommand command)
- {
- ArgumentNullException.ThrowIfNull(contextAware);
- ArgumentNullException.ThrowIfNull(command);
-
- var context = contextAware.GetContext();
- context.SendCommand(command);
- }
-
- ///
- /// 发送一个带返回值的命令
- ///
- /// 命令执行结果类型
- /// 实现 IContextAware 接口的对象
- /// 要发送的命令
- /// 命令执行结果
- /// 当 contextAware 或 command 为 null 时抛出
- public static TResult SendCommand(this IContextAware contextAware, ICommand command)
- {
- ArgumentNullException.ThrowIfNull(contextAware);
- ArgumentNullException.ThrowIfNull(command);
-
- var Context = contextAware.GetContext();
- return Context.SendCommand(command);
- }
-
///
/// 发送并异步执行一个无返回值的命令
///
@@ -116,8 +84,8 @@ public static class ContextAwareExtensions
ArgumentNullException.ThrowIfNull(contextAware);
ArgumentNullException.ThrowIfNull(command);
- var Context = contextAware.GetContext();
- await Context.SendCommandAsync(command);
+ var context = contextAware.GetContext();
+ await context.SendCommandAsync(command);
}
///
@@ -134,27 +102,11 @@ public static class ContextAwareExtensions
ArgumentNullException.ThrowIfNull(contextAware);
ArgumentNullException.ThrowIfNull(command);
- var Context = contextAware.GetContext();
- return await Context.SendCommandAsync(command);
- }
-
- ///
- /// 发送一个事件
- ///
- /// 命令执行结果类型
- /// 实现 IContextAware 接口的对象
- /// 要发送的命令
- /// 命令执行结果
- /// 当 contextAware 或 command 为 null 时抛出
- public static TResult SendCommand(this IContextAware contextAware, ICommand command)
- {
- ArgumentNullException.ThrowIfNull(contextAware);
- ArgumentNullException.ThrowIfNull(command);
-
var context = contextAware.GetContext();
- return context.SendCommand(command);
+ return await context.SendCommandAsync(command);
}
+
///
/// 发送一个事件
///
@@ -184,6 +136,39 @@ public static class ContextAwareExtensions
context.SendEvent(e);
}
+ ///
+ /// 发送一个事件
+ ///
+ /// 命令执行结果类型
+ /// 实现 IContextAware 接口的对象
+ /// 要发送的命令
+ /// 命令执行结果
+ /// 当 contextAware 或 command 为 null 时抛出
+ public static TResult SendCommand(this IContextAware contextAware, ICommand command)
+ {
+ ArgumentNullException.ThrowIfNull(contextAware);
+ ArgumentNullException.ThrowIfNull(command);
+
+ var context = contextAware.GetContext();
+ return context.SendCommand(command);
+ }
+
+ ///
+ /// 发送一个无返回结果的命令
+ ///
+ /// 实现 IContextAware 接口的对象
+ /// 要发送的命令
+ /// 当 contextAware 或 command 为 null 时抛出
+ public static void SendCommand(this IContextAware contextAware, ICommand command)
+ {
+ ArgumentNullException.ThrowIfNull(contextAware);
+ ArgumentNullException.ThrowIfNull(command);
+
+ var context = contextAware.GetContext();
+ context.SendCommand(command);
+ }
+
+
///
/// 注册事件处理器
///