private void NotifyMemberAccess(object value, MemberInfo memberInfo) { if (memberInfo is PropertyInfo && value is INotifyPropertyChanged) { lock (this) { List <MemberInfo> RegisteredProperties; if (this.propertyNotifications.TryGetValue(value, out RegisteredProperties) == false) { DebugLogger.WriteLine(this, LoggingLevel.Verbose, () => $"Attaching changing event on value '{value}'"); DebugLogger.WriteLine(this, LoggingLevel.Verbose, () => $"Adding property '{memberInfo.Name}' to changing event of value '{value}'"); INotifyPropertyChanged NotifyPropertyChanged = (INotifyPropertyChanged)value; PropertyChangedEventHandler Handler = WeakDelegate.Connect <NotifyChangeExpression <TYpeOfExpression>, INotifyPropertyChanged, PropertyChangedEventHandler, PropertyChangedEventArgs>( this, NotifyPropertyChanged, (target, sender, e) => target.NotifyPropertyChanged(sender, e), (source, handler) => source.PropertyChanged -= handler ); NotifyPropertyChanged.PropertyChanged += Handler; this.deregistrations.Add(delegate { NotifyPropertyChanged.PropertyChanged -= Handler; }); RegisteredProperties = new List <MemberInfo>(); this.propertyNotifications.Add(value, RegisteredProperties); } RegisteredProperties.Add(memberInfo); } } }
private void DetachEventsFromProperty() { RegisteredProperties.ToList().ForEach(p => p.PropertyChanged -= OnPropertyChanged); }
private void AttachEventsToViewModelProperty() { RegisteredProperties.ToList().ForEach(p => p.PropertyChanged += OnPropertyChanged); }
internal static IEnumerable <LinqPropertyBase> RegisteredPropertiesForOwnerType(Type ownerType) => RegisteredProperties.Where(p => p.OwnerType == ownerType);