GFramework/GFramework.Core/extensions/CanRegisterEventExtensions.cs
GwWuYou e204f899ba refactor(core): 重构框架命名空间为GFramework.Core
- 将所有framework命名空间下的类迁移至GFramework.Core命名空间
- 更新所有相关using引用从framework到Core
- 重命名项目文件夹及文件路径以匹配新的命名空间结构
- 在解决方案中添加GFramework.Core项目引用
- 配置项目依赖关系并移除旧的Generator引用冲突
- 创建独立的GFramework.Core.csproj项目文件支持多目标框架
2025-12-10 08:51:17 +08:00

29 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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) =>
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);
}