Esempio n. 1
0
 public NotifierEntry(Notifier notifier, NotifierProperty property, Func <object, object> getter)
 {
     Notifier = notifier;
     Property = property;
     Getter   = getter;
     SetValue(getter(null));
 }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public bool Set <T>(object target, T value, NotifierProperty property, Action <T, T> postUpdateAction = null)
        {
            var isnew = false;

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

            var old = isnew?default(T):entry.GetValue <T>();

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

            return(false);
        }
Esempio n. 4
0
 public T Get <T>(object target, Func <T, T> getter, NotifierProperty property, Action postUpdateAction = null)
 {
     try
     {
         return(Entries.GetOrAdd(property,
                                 p => p.GetNewEntry(this, 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));
     }
 }
Esempio n. 5
0
 public bool IsSet(NotifierProperty property) => Entries.ContainsKey(property);