Example #1
0
        public static void Subscribe(this INotifyPropertyChanged n)
        {
            var notifier = n.GetNotifier();

            foreach (var method in n.GetType().GetMethods())
            {
                foreach (var triggedOn in method.GetCustomAttributes().OfType <TriggedOn>())
                {
                    switch (method.GetParameters().Length)
                    {
                    case 0:
                        n.Subscribe(args => method.Invoke(n, null), triggedOn.Pathes);
                        break;

                    case 1:
                        n.Subscribe(args => method.Invoke(n, new object[] { args }), triggedOn.Pathes);
                        break;
                    }
                }
            }

            foreach (var property in n.GetType().GetProperties())
            {
                var name = property.Name;
                foreach (var triggedOn in property.GetCustomAttributes().OfType <TriggedOn>())
                {
                    if (typeof(ITriggable).IsAssignableFrom(property.PropertyType))
                    {
                        n.Subscribe(a =>
                        {
                            if (notifier.IsSet(property))
                            {
                                notifier.Get <ITriggable>(n, null, name).OnTrigged();
                            }
                            else
                            {
                                notifier.OnPropertyChanged(name);
                            }
                            //property.GetMethod.Invoke(n, null);
                        }, triggedOn.Pathes);
                    }
                    else
                    {
                        n.Subscribe(a =>
                        {
                            if (notifier.IsSet(property))
                            {
                                notifier.Update(property);
                            }
                            else
                            {
                                notifier.OnPropertyChanged(name);
                            }
                            //property.GetMethod.Invoke(n, null);
                        }, triggedOn.Pathes);
                    }
                }
            }
        }
Example #2
0
 public static void SubscribeNotifier(this INotifyPropertyChanged n) => n.GetNotifier().Subscribe(n);
Example #3
0
 public static bool Set <T>(this INotifyPropertyChanged n,
                            T value,
                            [CallerMemberName] string propertyName = null)
 => n.GetNotifier().Set(n, value, propertyName, null);
Example #4
0
 public static bool Set <T>(this INotifyPropertyChanged n,
                            T value,
                            Action <T, T> postUpdateAction,
                            [CallerMemberName] string propertyName = null)
 => n.GetNotifier().Set(n, value, propertyName, postUpdateAction);
Example #5
0
 public static T Get <T>(this INotifyPropertyChanged n, Func <T, T> getter,
                         [CallerMemberName] string propertyName = null)
 => n.GetNotifier().Get <T>(n, getter, propertyName);
Example #6
0
 public static T Get <T>(this INotifyPropertyChanged n,
                         [CallerMemberName] string propertyName = null)
 => n.GetNotifier().Get <T>(n, old => default(T), propertyName);
Example #7
0
 public static void Remove(this INotifyPropertyChanged n, PropertyChangedEventHandler handler)
 => n.GetNotifier().Remove(n, handler);
Example #8
0
 public static SuspenderToken Suspend(this INotifyPropertyChanged n)
 => n.GetNotifier().Suspend.Get();