1
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user