public NotifierEntry(Notifier notifier, NotifierProperty property, Func <object, object> getter) { Notifier = notifier; Property = property; Getter = getter; Value = getter(null); }
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); }
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); }
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)); } }
public bool IsSet(NotifierProperty property) => Entries.ContainsKey(property);