public override void Initialize(EntityExtensions extensions) { if (!RuleDebugger.CheckNoNotifyPropertyChangedWarning(extensions.Target)) { return; } var r = new RecursionObject { Extensions = extensions, Strategy = this }; // Wire notify property changed ((INotifyPropertyChanged)extensions.Target).PropertyChanged += r.OnPropertyChanged; // Wire notify collection changed foreach (var collection in GetCollections(extensions.Target)) { if (RuleDebugger.CheckNoNotifyCollectionChangedWarning(collection)) { ((INotifyCollectionChanged)collection).CollectionChanged += r.OnCollectionChanged; } } // Set parent foreach (var childObject in GetAllChildObjects(extensions.Target)) { childObject.Parent = extensions; } }
internal void OnPropertyChanged(object sender, PropertyChangedEventArgs e) { var extensions = Strategy.GetProperty(Extensions.Target, e.PropertyName); if (extensions != null) { // Set parent to null object oldValue; _objects.TryGetValue(e.PropertyName, out oldValue); if (oldValue != null) { ((IEntityExtensions)oldValue).Parent = null; } // Set parent to value extensions.Parent = Extensions; _objects[e.PropertyName] = extensions; } var collection = Strategy.GetCollection(Extensions.Target, e.PropertyName); if (RuleDebugger.CheckNoNotifyCollectionChangedWarning(collection)) { var ncc = (INotifyCollectionChanged)collection; // Unwire collection object oldValue; if (_objects.TryGetValue(e.PropertyName, out oldValue)) { var oldncc = (INotifyCollectionChanged)oldValue; oldncc.CollectionChanged -= OnCollectionChanged; // Set old to null foreach (var element in Strategy.GetCollectionElements((IEnumerable)oldncc)) { element.Parent = null; } } // Wire new ncc.CollectionChanged += OnCollectionChanged; // Set child parent to value foreach (var element in Strategy.GetCollectionElements(collection)) { element.Parent = Extensions; } } //// Todo: Item[] }