using System; using System.Reflection; namespace BITKit { public interface IWrapper { public object Obj { get; set; } } public interface IWrapper:IWrapper { public T Value { get; set; } } public class ValueWrapper : IWrapper { public T Value { get; set; }=default; public object Obj { get => Value; set => Value = (T)value; } } public class FieldWrapper : IWrapper { private readonly FieldInfo _field; private readonly object _target; public FieldWrapper(FieldInfo field, object target) { _field = field; _target = target ?? throw new ArgumentNullException(nameof(target)); } public T Value { get => (T)_field.GetValue(_target); set => _field.SetValue(_target, value); } public object Obj { get => _field.GetValue(_target); set => _field.SetValue(_target, value); } } public class FuncWrapper : IWrapper { private readonly Func _get; private readonly Action _set; public FuncWrapper(Func get, Action set) { _get = get; _set = set; } public T Value { get => _get(); set => _set(value); } public object Obj { get => _get(); set => _set((T)value); } } }