From 270411c66c3a7200b108319ed074827c79f55bbd Mon Sep 17 00:00:00 2001
From: GeWuYou <95328647+GeWuYou@users.noreply.github.com>
Date: Thu, 25 Dec 2025 08:25:12 +0800
Subject: [PATCH] =?UTF-8?q?refactor(architecture):=20=E4=BC=98=E5=8C=96?=
=?UTF-8?q?=E4=BA=8B=E4=BB=B6=E7=B3=BB=E7=BB=9F=E6=B3=9B=E5=9E=8B=E7=BA=A6?=
=?UTF-8?q?=E6=9D=9F=E5=92=8C=E5=91=BD=E5=90=8D=E8=A7=84=E8=8C=83?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 为 SendEvent 方法添加 class 约束以确保类型安全
- 统一泛型参数命名从 T 到 TEvent 提高可读性
- 移除不必要的 using 语句简化文件依赖
- 保持事件发送和注册功能的原有行为不变
---
.../architecture/ArchitectureRuntime.cs | 2 +-
.../architecture/IArchitectureRuntime.cs | 19 ++++++++-----------
2 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/GFramework.Core/architecture/ArchitectureRuntime.cs b/GFramework.Core/architecture/ArchitectureRuntime.cs
index dfe5af2..6ee87bc 100644
--- a/GFramework.Core/architecture/ArchitectureRuntime.cs
+++ b/GFramework.Core/architecture/ArchitectureRuntime.cs
@@ -67,7 +67,7 @@ public class ArchitectureRuntime(IArchitectureContext context) : IArchitectureRu
///
/// 事件类型
/// 要发布的事件实例
- public void SendEvent(TEvent e)
+ public void SendEvent(TEvent e) where TEvent : class
{
_context.SendEvent(e);
}
diff --git a/GFramework.Core/architecture/IArchitectureRuntime.cs b/GFramework.Core/architecture/IArchitectureRuntime.cs
index 5433195..37ccb67 100644
--- a/GFramework.Core/architecture/IArchitectureRuntime.cs
+++ b/GFramework.Core/architecture/IArchitectureRuntime.cs
@@ -1,9 +1,6 @@
using GFramework.Core.command;
using GFramework.Core.events;
-using GFramework.Core.model;
using GFramework.Core.query;
-using GFramework.Core.system;
-using GFramework.Core.utility;
namespace GFramework.Core.architecture;
@@ -39,28 +36,28 @@ public interface IArchitectureRuntime
///
/// 发送无参事件
///
- /// 事件类型,必须具有无参构造函数
- void SendEvent() where T : new();
+ /// 事件类型,必须具有无参构造函数
+ void SendEvent() where TEvent : new();
///
/// 发送指定的事件实例
///
- /// 事件类型
+ /// 事件类型
/// 要发送的事件实例
- void SendEvent(T e);
+ void SendEvent(TEvent e) where TEvent : class;
///
/// 注册事件监听器
///
- /// 事件类型
+ /// 事件类型
/// 事件触发时的回调方法
/// 用于取消注册的句柄
- IUnRegister RegisterEvent(Action onEvent);
+ IUnRegister RegisterEvent(Action onEvent);
///
/// 取消注册事件监听器
///
- /// 事件类型
+ /// 事件类型
/// 要取消注册的事件回调方法
- void UnRegisterEvent(Action onEvent);
+ void UnRegisterEvent(Action onEvent);
}
\ No newline at end of file