Esempio n. 1
0
            public static EarListener Start(Ear <TOutput> ear, INotifyPropertyChanged target, int index)
            {
                var listener = new EarListener(ear, index);

                target.PropertyChanged += listener.TargetOnPropertyChanged;
                return(listener);
            }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
 public static void Then <T>(this Ear <T> ear, Action handler)
 {
     ear.Then((_, __, ___) => handler());
 }