/// <summary> /// Run all action for collection changed /// </summary> /// <param name="property"></param> /// <param name="args"></param> public void RunCollection(string property, MvbCollectionUpdateArgs args) { ICollection <Tuple <WeakReference, Action <MvbCollectionUpdateArgs> > > value; if (!this._runCollectionDictionary.TryGetValue(property, out value)) { return; } var toRemove = new List <Tuple <WeakReference, Action <MvbCollectionUpdateArgs> > >(); // Run every action on live subscriber foreach (var tuple in value) { if (tuple.Item1.IsAlive) { this._uiRunner.Run(tuple.Item2, args); } else { toRemove.Add(tuple); } } // Clear action on dead objects foreach (var toRemoveItem in toRemove) { value.Remove(toRemoveItem); } }
private void ActiveListenerOnObservableCollection(object obj, string propertyNameSuffix = null) { var typeInfo = obj.GetType().GetTypeInfo(); foreach (var info in typeInfo.DeclaredProperties) { var isMvbCollection = info.PropertyType.GetTypeInfo().ImplementedInterfaces.Contains(typeof(IMvbCollection)); if (!isMvbCollection) { continue; } var obserableProp = (IMvbCollection)info.GetValue(obj, null); if (obserableProp == null) { continue; } var runPropertyName = propertyNameSuffix != null ? $"{propertyNameSuffix}.{info.Name}" : info.Name; runPropertyName = runPropertyName.TrimStart('.'); obserableProp.CollectionChanged += (sender, args) => { var mvbArgs = new MvbCollectionUpdateArgs { MvbUpdateAction = MvbUpdateAction.CollectionChanged, NotifyCollectionChangedEventArgs = args }; this.RunCollection(runPropertyName, mvbArgs); }; obserableProp.MvbItemCollectionChanged += (sender, args) => { var mvbArgs = new MvbCollectionUpdateArgs { MvbUpdateAction = MvbUpdateAction.ItemChanged, MvbCollectionItemChanged = args }; this.RunCollection(info.Name, mvbArgs); }; } }
/// <summary> /// Run all action for collection changed /// </summary> /// <param name="property"></param> /// <param name="args"></param> public void RunCollection <TSource>(Expression <Func <TSource, object> > property, MvbCollectionUpdateArgs args) where TSource : MvbBase { var propName = this.GetCompositePropertyName(property); this.RunCollection(propName, args); }