mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 19:03:29 +08:00
- 调整了 Architecture 类中字段和方法的布局,提升可读性 - 优化了命令执行逻辑,明确区分有无返回值的命令处理 - 规范了接口和抽象类的注释格式,增强文档清晰度 - 统一了代码风格,对齐缩进与换行符使用 - 补充了事件系统中泛型事件类的功能实现 - 完善了 README 文档中的条目结构和内容表述
32 lines
1.2 KiB
C#
32 lines
1.2 KiB
C#
using GFramework.Core.events;
|
||
|
||
namespace GFramework.Core.extensions;
|
||
|
||
/// <summary>
|
||
/// 事件注册扩展类,提供ICanRegisterEvent接口的扩展方法用于注册和注销事件
|
||
/// </summary>
|
||
public static class CanRegisterEventExtensions
|
||
{
|
||
/// <summary>
|
||
/// 注册指定类型的事件处理函数
|
||
/// </summary>
|
||
/// <typeparam name="T">事件数据类型</typeparam>
|
||
/// <param name="self">实现ICanRegisterEvent接口的对象实例</param>
|
||
/// <param name="onEvent">事件处理回调函数</param>
|
||
/// <returns>返回事件注销器接口,可用于后续注销事件</returns>
|
||
public static IUnRegister RegisterEvent<T>(this ICanRegisterEvent self, Action<T> onEvent)
|
||
{
|
||
return self.GetArchitecture().RegisterEvent(onEvent);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 注销指定类型的事件处理函数
|
||
/// </summary>
|
||
/// <typeparam name="T">事件数据类型</typeparam>
|
||
/// <param name="self">实现ICanRegisterEvent接口的对象实例</param>
|
||
/// <param name="onEvent">要注销的事件处理回调函数</param>
|
||
public static void UnRegisterEvent<T>(this ICanRegisterEvent self, Action<T> onEvent)
|
||
{
|
||
self.GetArchitecture().UnRegisterEvent(onEvent);
|
||
}
|
||
} |