2019-09-28 18:17:39 +00:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace cylvester
|
|
|
|
{
|
2019-10-01 13:08:35 +00:00
|
|
|
interface IChangeObserver<T> where T : IComparable<T>
|
2019-09-28 18:17:39 +00:00
|
|
|
{
|
2019-10-01 13:08:35 +00:00
|
|
|
T Value { set; }
|
2019-09-28 18:17:39 +00:00
|
|
|
event Action ValueChanged;
|
|
|
|
}
|
|
|
|
|
2019-10-01 13:08:35 +00:00
|
|
|
public class ChangeObserver<T> : IChangeObserver<T> where T : IComparable<T>
|
2019-09-28 18:17:39 +00:00
|
|
|
{
|
2019-10-01 13:08:35 +00:00
|
|
|
private T value_;
|
|
|
|
public ChangeObserver(T initial)
|
2019-09-28 18:17:39 +00:00
|
|
|
{
|
|
|
|
Value = initial;
|
|
|
|
}
|
|
|
|
|
|
|
|
public T Value
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value.CompareTo(value_) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
value_ = value;
|
|
|
|
ValueChanged.Invoke();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public event Action ValueChanged = () => { };
|
|
|
|
}
|
|
|
|
}
|