Example #1
0
 public NotifierEntry(Notifier notifier, NotifierProperty property, Func <object, object> getter)
 {
     Notifier = notifier;
     Property = property;
     Getter   = getter;
     Value    = getter(null);
 }
Example #2
0
        public bool Set <T>(object target, T value, NotifierProperty property, Action <T, T> postUpdateAction = null)
        {
            bool isnew = false;

            var entry = Entries.GetOrAdd(property, (oldValue) =>
            {
                isnew = true;
                return(new NotifierEntry(this, property, n => value));
            }
                                         );

            if (isnew)
            {
                OnPropertyChanged(new NotifierPropertyChangedEventArgs(property.Name, default(T), value));
                return(true);
            }

            var old = entry.GetValue <T>();

            if (entry.SetValue(value))
            {
                postUpdateAction?.Invoke(old, value);
                OnPropertyChanged(new NotifierPropertyChangedEventArgs(property.Name, old, value));
                return(true);
            }

            return(false);
        }
Example #3
0
        public bool Update(NotifierProperty property)
        {
            if (Entries.TryGetValue(property, out var entry))
            {
                var old = entry.GetValue <object>();

                if (entry.Update())
                {
                    OnPropertyChanged(new NotifierPropertyChangedEventArgs(property.Name, old, entry.GetValue <object>()));
                    return(true);
                }
            }
            return(false);
        }
Example #4
0
 public T Get <T>(object target, Func <T, T> getter, NotifierProperty property, Action postUpdateAction = null)
 {
     try
     {
         return(Entries.GetOrAdd(property,
                                 e => new NotifierEntry(this, property, a => getter.Invoke((T)(a ?? default(T))))).GetValue <T>());
     }
     catch (PropertyNotReady ex)
     {
         if (Entries.TryRemove(property, out var e))
         {
         }
         ;
         return((T)ex.ReturnValue);
     }
     catch (NullReferenceException ex)
     {
         if (Entries.TryRemove(property, out var e))
         {
         }
         return(default(T));
     }
 }
Example #5
0
 public bool IsSet(NotifierProperty property) => Entries.ContainsKey(property);