GwWuYou 5aa11ddc41 feat(architecture): 添加架构核心组件与命令模式实现
- 新增 Architecture 基类与 IArchitecture 接口,实现单例模式与组件注册管理
- 集成 IOC 容器支持系统、模型、工具的依赖注入与生命周期管理
- 实现命令模式基础类 AbstractCommand 与接口 ICommand,支持带返回值命令
- 提供事件系统集成,支持事件的发布与订阅机制
- 添加控制器接口 IController,整合命令发送、事件注册与模型获取能力
- 创建详细的 README 文档说明各组件使用方式与设计模式应用
- 支持命令、查询、事件的统一调度与解耦通信机制
2025-12-09 15:32:17 +08:00

54 lines
1.6 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.framework.extensions;
namespace GFramework.framework.events;
/// <summary>
/// OrEvent类用于实现事件的或逻辑组合当任意一个注册的事件触发时都会触发OrEvent本身
/// </summary>
public class OrEvent : IUnRegisterList
{
/// <summary>
/// 将指定的事件与当前OrEvent进行或逻辑组合
/// </summary>
/// <param name="easyEvent">要组合的事件对象</param>
/// <returns>返回当前OrEvent实例支持链式调用</returns>
public OrEvent Or(IEasyEvent easyEvent)
{
easyEvent.Register(Trigger).AddToUnregisterList(this);
return this;
}
private Action _mOnEvent = () => { };
/// <summary>
/// 注册事件处理函数
/// </summary>
/// <param name="onEvent">要注册的事件处理函数</param>
/// <returns>返回一个可取消注册的对象</returns>
public IUnRegister Register(Action onEvent)
{
_mOnEvent += onEvent;
return new DefaultUnRegister(() => { UnRegister(onEvent); });
}
/// <summary>
/// 取消注册指定的事件处理函数
/// </summary>
/// <param name="onEvent">要取消注册的事件处理函数</param>
public void UnRegister(Action onEvent)
{
_mOnEvent -= onEvent;
this.UnRegisterAll();
}
/// <summary>
/// 触发所有已注册的事件处理函数
/// </summary>
private void Trigger() => _mOnEvent?.Invoke();
/// <summary>
/// 获取取消注册列表
/// </summary>
public List<IUnRegister> UnregisterList { get; } = new List<IUnRegister>();
}