mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-23 03:04:29 +08:00
- 统一调整代码注释的缩进格式,保持文档注释的一致性 - 简化对象初始化语法,移除不必要的参数名称指定 - 优化条件语句结构,移除多余的花括号 - 调整方法实现格式,使用表达式主体语法简化代码 - 标准化代码缩进和空格使用,提升代码可读性 - [skip ci]
39 lines
1.4 KiB
C#
39 lines
1.4 KiB
C#
using GFramework.Core.Abstractions.events;
|
|
|
|
namespace GFramework.Core.property;
|
|
|
|
/// <summary>
|
|
/// 可绑定属性注销器类,用于取消注册可绑定属性的值变化监听
|
|
/// </summary>
|
|
/// <typeparam name="T">可绑定属性的值类型</typeparam>
|
|
/// <param name="bindableProperty">需要注销的可绑定属性实例</param>
|
|
/// <param name="onValueChanged">需要注销的值变化回调函数</param>
|
|
public class BindablePropertyUnRegister<T>(BindableProperty<T> bindableProperty, Action<T> onValueChanged)
|
|
: IUnRegister
|
|
{
|
|
/// <summary>
|
|
/// 获取或设置可绑定属性实例
|
|
/// </summary>
|
|
public BindableProperty<T>? BindableProperty { get; set; } = bindableProperty;
|
|
|
|
/// <summary>
|
|
/// 获取或设置值变化时的回调函数
|
|
/// </summary>
|
|
public Action<T>? OnValueChanged { get; set; } = onValueChanged;
|
|
|
|
/// <summary>
|
|
/// 执行注销操作,取消注册值变化监听并清理引用
|
|
/// </summary>
|
|
public void UnRegister()
|
|
{
|
|
// 检查两个引用都不为null时才执行注销操作
|
|
if (BindableProperty != null && OnValueChanged != null)
|
|
// 调用可绑定属性的注销方法,传入值变化回调函数
|
|
BindableProperty.UnRegister(OnValueChanged);
|
|
|
|
// 清理属性引用
|
|
BindableProperty = null;
|
|
// 清理回调函数引用
|
|
OnValueChanged = null;
|
|
}
|
|
} |