using System; namespace IFramework { /// /// 可观测树值 /// /// public class ObservableValue : ObservableObject { /// /// 默认的名字 /// public const string ValuePropertyName = "value"; private T _value; /// /// 具体的数值 /// public T value { get { return GetProperty(ref _value, ValuePropertyName); } set { SetProperty(ref _value, value, ValuePropertyName); } } /// /// Ctor /// /// public ObservableValue(T value) : base() { _value = value; } /// /// 注册 value 变化监听 /// /// public void Subscribe(Action listener) { base.Subscribe(ValuePropertyName, listener); } /// /// 取消注册 value 变化监听 /// /// public void UnSubscribe(Action listener) { base.UnSubscribe(ValuePropertyName, listener); } /// /// 方便书写,缩减代码 /// /// public static implicit operator T(ObservableValue value) { return value.value; } } }