This commit is contained in:
CortexCore
2025-01-09 17:49:38 +08:00
parent 0287c1a2fc
commit 01e7e4e35e
5 changed files with 159 additions and 16 deletions

View File

@@ -16,6 +16,34 @@ namespace BITKit
public T Value { get; set; }=default;
public object Obj { get => Value; set => Value = (T)value; }
}
public class PropertyWrapper<T> : IWrapper<T>
{
private readonly PropertyInfo _field;
private readonly object _target;
public event Action<T, T> OnValueChanged;
public PropertyWrapper(PropertyInfo field, object target)
{
_field = field;
_target = target ?? throw new ArgumentNullException(nameof(target));
}
public T Value
{
get => (T)_field.GetValue(_target);
set
{
var prev = Value;
_field.SetValue(_target, value);
OnValueChanged?.Invoke(prev, value);
}
}
public object Obj
{
get => _field.GetValue(_target);
set => _field.SetValue(_target, value);
}
}
public class FieldWrapper<T> : IWrapper<T>
{
private readonly FieldInfo _field;