public static EarListener Start(Ear <TOutput> ear, INotifyPropertyChanged target, int index) { var listener = new EarListener(ear, index); target.PropertyChanged += listener.TargetOnPropertyChanged; return(listener); }
private EarListener(Ear <TOutput> ear, int index) { this.ear = ear ?? throw new ArgumentNullException(nameof(ear)); if (index < 0 || index >= ear.path.Length) { throw new IndexOutOfRangeException(nameof(index)); } this.index = index; }
public static Ear <TOutput> Listen <TOutput>(this INotifyPropertyChanged target, params PropertyInfo[] path) { var ear = new Ear <TOutput>(target, path); if (target is IDisposableHost host) { host.AddDisposable(ear); } return(ear); }
public static void Then <T>(this Ear <T> ear, EarValueChangedHandler <T> handler) { // var semaphore = new Semaphore(1, 1); var instrumentedHandler = new EarValueChangedHandler <T>((e, oldValue, newValue) => { // if (semaphore.WaitOne()) // { handler(e, oldValue, newValue); // } }); ear.ValueChanged += instrumentedHandler; ear.AddDisposable(() => ear.ValueChanged -= handler); }
public static void Then <T>(this Ear <T> ear, Action handler) { ear.Then((_, __, ___) => handler()); }