mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-25 13:33:28 +08:00
refactor(property): 优化可绑定属性和事件系统实现
- 为BindableProperty添加属性值变化事件回调委托的XML文档注释 - 为BindableProperty添加存储属性实际值的受保护字段的XML文档注释 - 统一Event类中泛型参数命名规范,将TK改为Tk以保持一致性 - 更新Event类中所有相关方法和字段的泛型参数类型引用 - 修正Event类中Trigger方法的参数类型声明
This commit is contained in:
parent
222c481ffa
commit
ed09ab7009
@ -66,14 +66,14 @@ public class Event<T> : IEvent
|
|||||||
/// 提供事件注册、注销和触发功能。
|
/// 提供事件注册、注销和触发功能。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">第一个参数类型。</typeparam>
|
/// <typeparam name="T">第一个参数类型。</typeparam>
|
||||||
/// <typeparam name="TK">第二个参数类型。</typeparam>
|
/// <typeparam name="Tk">第二个参数类型。</typeparam>
|
||||||
public class Event<T, TK> : IEvent
|
public class Event<T, Tk> : IEvent
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 存储已注册的双参数事件处理委托。
|
/// 存储已注册的双参数事件处理委托。
|
||||||
/// 默认为空操作(no-op)委托。
|
/// 默认为空操作(no-op)委托。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private Action<T, TK>? _mOnEvent = (_, _) => { };
|
private Action<T, Tk>? _mOnEvent = (_, _) => { };
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 显式实现 IEvent 接口中的 Register 方法。
|
/// 显式实现 IEvent 接口中的 Register 方法。
|
||||||
@ -85,7 +85,7 @@ public class Event<T, TK> : IEvent
|
|||||||
{
|
{
|
||||||
return Register(Action);
|
return Register(Action);
|
||||||
|
|
||||||
void Action(T _, TK __)
|
void Action(T _, Tk __)
|
||||||
{
|
{
|
||||||
onEvent();
|
onEvent();
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ public class Event<T, TK> : IEvent
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="onEvent">要注册的事件处理方法。</param>
|
/// <param name="onEvent">要注册的事件处理方法。</param>
|
||||||
/// <returns>IUnRegister 对象,用于稍后注销该事件监听器。</returns>
|
/// <returns>IUnRegister 对象,用于稍后注销该事件监听器。</returns>
|
||||||
public IUnRegister Register(Action<T, TK> onEvent)
|
public IUnRegister Register(Action<T, Tk> onEvent)
|
||||||
{
|
{
|
||||||
_mOnEvent += onEvent;
|
_mOnEvent += onEvent;
|
||||||
return new DefaultUnRegister(() => { UnRegister(onEvent); });
|
return new DefaultUnRegister(() => { UnRegister(onEvent); });
|
||||||
@ -106,7 +106,7 @@ public class Event<T, TK> : IEvent
|
|||||||
/// 取消指定的双参数事件监听器。
|
/// 取消指定的双参数事件监听器。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="onEvent">需要被注销的事件处理方法。</param>
|
/// <param name="onEvent">需要被注销的事件处理方法。</param>
|
||||||
public void UnRegister(Action<T, TK> onEvent)
|
public void UnRegister(Action<T, Tk> onEvent)
|
||||||
{
|
{
|
||||||
_mOnEvent -= onEvent;
|
_mOnEvent -= onEvent;
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ public class Event<T, TK> : IEvent
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="t">第一个参数。</param>
|
/// <param name="t">第一个参数。</param>
|
||||||
/// <param name="k">第二个参数。</param>
|
/// <param name="k">第二个参数。</param>
|
||||||
public void Trigger(T t, TK k)
|
public void Trigger(T t, Tk k)
|
||||||
{
|
{
|
||||||
_mOnEvent?.Invoke(t, k);
|
_mOnEvent?.Invoke(t, k);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,14 @@ namespace GFramework.Core.property;
|
|||||||
/// <param name="defaultValue">属性的默认值</param>
|
/// <param name="defaultValue">属性的默认值</param>
|
||||||
public class BindableProperty<T>(T defaultValue = default!) : IBindableProperty<T>
|
public class BindableProperty<T>(T defaultValue = default!) : IBindableProperty<T>
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 属性值变化事件回调委托,当属性值发生变化时被调用
|
||||||
|
/// </summary>
|
||||||
private Action<T>? _mOnValueChanged;
|
private Action<T>? _mOnValueChanged;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 存储属性实际值的受保护字段
|
||||||
|
/// </summary>
|
||||||
protected T MValue = defaultValue;
|
protected T MValue = defaultValue;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user