Compare commits

..

No commits in common. "6788dfaa4be12b3fbb5bd1872bc4ad41d594826a" and "000a079985cba24f7aa6ed5943a0294ded4a7b5d" have entirely different histories.

2 changed files with 10 additions and 55 deletions

View File

@ -1,5 +1,4 @@
using System;
using Cysharp.Threading.Tasks;
namespace BITKit
{
@ -71,22 +70,6 @@ namespace BITKit
return Allow ? Value : other.Invoke();
}
public async UniTask<T> IfNotAllowAsync(Func<UniTask<T>> func)
{
return Allow ? Value : await func.Invoke();
}
public async UniTask<T> SetValueThenAllowAsync(Func<UniTask<T>> func)
{
if (Allow)
{
return value;
}
value = await func.Invoke();
allow = true;
return value;
}
public void SetValueThenAllow(T newValue)
{
value = newValue;

View File

@ -9,37 +9,19 @@ namespace BITKit
}
public interface IWrapper<T>:IWrapper
{
public Action<T, T> OnValueChanged { get; set; }
public T Value { get; set; }
}
public class ValueWrapper<T> : IWrapper<T>
{
public Action<T, T> OnValueChanged { get; set; }
public T Value
{
get => _value;
set
{
var prev = _value;
_value = value;
OnValueChanged?.Invoke(prev,value);
}
}
private T _value = typeof(T) == typeof(string) ? string.Empty.As<T>() : Activator.CreateInstance<T>();
public object Obj
{
get => Value;
set => Value = (T)value;
}
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 Action<T, T> OnValueChanged { get; set; }
public event Action<T, T> OnValueChanged;
public PropertyWrapper(PropertyInfo field, object target)
{
_field = field;
@ -58,8 +40,8 @@ namespace BITKit
public object Obj
{
get => Value;
set => Value = (T)value;
get => _field.GetValue(_target);
set => _field.SetValue(_target, value);
}
}
public class FieldWrapper<T> : IWrapper<T>
@ -71,23 +53,16 @@ namespace BITKit
_field = field;
_target = target ?? throw new ArgumentNullException(nameof(target));
}
public Action<T, T> OnValueChanged { get; set; }
public T Value
{
get => (T)_field.GetValue(_target);
set
{
OnValueChanged?.Invoke(Value, value);
_field.SetValue(_target, value);
}
set => _field.SetValue(_target, value);
}
public object Obj
{
get => Value;
set => Value = (T)value;
get => _field.GetValue(_target);
set => _field.SetValue(_target, value);
}
}
public class FuncWrapper<T> : IWrapper<T>
@ -99,9 +74,6 @@ namespace BITKit
_get = get;
_set = set;
}
public Action<T, T> OnValueChanged { get; set; }
public T Value
{
get => _get();
@ -110,8 +82,8 @@ namespace BITKit
public object Obj
{
get => Value;
set => Value = (T)value;
get => _get();
set => _set((T)value);
}
}
}