deepsource-autofix[bot] a30abdb4c3 refactor: simplify lambda expressions
This PR refactors numerous lambda expressions by removing unnecessary braces and streamlining single-statement lambdas throughout the codebase, improving readability and maintainability.

- Consider simplifying lambda when its body has a single statement: DeepSource flagged lambdas written with a block body for only one statement, causing extra verbosity. This update converts those to concise expression-bodied lambdas by stripping out the curly braces, applied across test assertions, event registrations, and unregister logic. The code is now cleaner and more consistent.

> This Autofix was generated by AI. Please review the change before merging.
2026-03-02 22:01:22 +08:00

39 lines
1022 B
C#

using GFramework.Core.Abstractions.events;
namespace GFramework.Core.events;
/// <summary>
/// 简单事件类,用于注册、注销和触发无参事件回调
/// </summary>
public class EasyEvent
{
private Action? _mOnEvent = () => { };
/// <summary>
/// 注册事件回调函数
/// </summary>
/// <param name="onEvent">要注册的事件回调函数</param>
/// <returns>用于注销事件的 unregister 对象</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;
}
/// <summary>
/// 触发所有已注册的事件回调函数
/// </summary>
public void Trigger()
{
_mOnEvent?.Invoke();
}
}