mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-25 21:34:28 +08:00
refactor(architecture): 优化事件系统泛型约束和命名规范
- 为 SendEvent 方法添加 class 约束以确保类型安全 - 统一泛型参数命名从 T 到 TEvent 提高可读性 - 移除不必要的 using 语句简化文件依赖 - 保持事件发送和注册功能的原有行为不变
This commit is contained in:
parent
5b7eaea142
commit
270411c66c
@ -67,7 +67,7 @@ public class ArchitectureRuntime(IArchitectureContext context) : IArchitectureRu
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TEvent">事件类型</typeparam>
|
/// <typeparam name="TEvent">事件类型</typeparam>
|
||||||
/// <param name="e">要发布的事件实例</param>
|
/// <param name="e">要发布的事件实例</param>
|
||||||
public void SendEvent<TEvent>(TEvent e)
|
public void SendEvent<TEvent>(TEvent e) where TEvent : class
|
||||||
{
|
{
|
||||||
_context.SendEvent(e);
|
_context.SendEvent(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,6 @@
|
|||||||
using GFramework.Core.command;
|
using GFramework.Core.command;
|
||||||
using GFramework.Core.events;
|
using GFramework.Core.events;
|
||||||
using GFramework.Core.model;
|
|
||||||
using GFramework.Core.query;
|
using GFramework.Core.query;
|
||||||
using GFramework.Core.system;
|
|
||||||
using GFramework.Core.utility;
|
|
||||||
|
|
||||||
namespace GFramework.Core.architecture;
|
namespace GFramework.Core.architecture;
|
||||||
|
|
||||||
@ -39,28 +36,28 @@ public interface IArchitectureRuntime
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 发送无参事件
|
/// 发送无参事件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">事件类型,必须具有无参构造函数</typeparam>
|
/// <typeparam name="TEvent">事件类型,必须具有无参构造函数</typeparam>
|
||||||
void SendEvent<T>() where T : new();
|
void SendEvent<TEvent>() where TEvent : new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 发送指定的事件实例
|
/// 发送指定的事件实例
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">事件类型</typeparam>
|
/// <typeparam name="TEvent">事件类型</typeparam>
|
||||||
/// <param name="e">要发送的事件实例</param>
|
/// <param name="e">要发送的事件实例</param>
|
||||||
void SendEvent<T>(T e);
|
void SendEvent<TEvent>(TEvent e) where TEvent : class;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 注册事件监听器
|
/// 注册事件监听器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">事件类型</typeparam>
|
/// <typeparam name="TEvent">事件类型</typeparam>
|
||||||
/// <param name="onEvent">事件触发时的回调方法</param>
|
/// <param name="onEvent">事件触发时的回调方法</param>
|
||||||
/// <returns>用于取消注册的句柄</returns>
|
/// <returns>用于取消注册的句柄</returns>
|
||||||
IUnRegister RegisterEvent<T>(Action<T> onEvent);
|
IUnRegister RegisterEvent<TEvent>(Action<TEvent> onEvent);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 取消注册事件监听器
|
/// 取消注册事件监听器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">事件类型</typeparam>
|
/// <typeparam name="TEvent">事件类型</typeparam>
|
||||||
/// <param name="onEvent">要取消注册的事件回调方法</param>
|
/// <param name="onEvent">要取消注册的事件回调方法</param>
|
||||||
void UnRegisterEvent<T>(Action<T> onEvent);
|
void UnRegisterEvent<TEvent>(Action<TEvent> onEvent);
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user