diff --git a/src/ObservableCollections/IObservableCollection.cs b/src/ObservableCollections/IObservableCollection.cs index efcfae7..b17a30c 100644 --- a/src/ObservableCollections/IObservableCollection.cs +++ b/src/ObservableCollections/IObservableCollection.cs @@ -37,6 +37,9 @@ namespace ObservableCollections object SyncRoot { get; } ISynchronizedViewFilter CurrentFilter { get; } + // TODO: add + event Action>? ViewChanged; + // TODO: remove event NotifyCollectionChangedEventHandler? RoutingCollectionChanged; event Action? CollectionStateChanged; diff --git a/src/ObservableCollections/Internal/NotifyCollectionChangedSynchronizedView.cs b/src/ObservableCollections/Internal/NotifyCollectionChangedSynchronizedView.cs index ee25a44..e6c4c3c 100644 --- a/src/ObservableCollections/Internal/NotifyCollectionChangedSynchronizedView.cs +++ b/src/ObservableCollections/Internal/NotifyCollectionChangedSynchronizedView.cs @@ -12,75 +12,62 @@ namespace ObservableCollections.Internal { readonly ISynchronizedView parent; readonly List listView; - readonly Func selector; - public SynchronizedViewList(ISynchronizedView parent, Func selector) + public SynchronizedViewList(ISynchronizedView parent) { this.parent = parent; - this.selector = selector; - parent.RoutingCollectionChanged += Parent_RoutingCollectionChanged; // TODO: -= + // TODO:add + parent.ViewChanged += Parent_ViewChanged; } - private void Parent_RoutingCollectionChanged(in NotifyCollectionChangedEventArgs e) + private void Parent_ViewChanged(SynchronizedViewChangedEventArgs e) { - // call in parent.lock. + // event is called inside lock(parent.SyncRoot) + // TODO: invoke in ICollectionEventDispatcher? + switch (e.Action) { - case NotifyCollectionChangedAction.Add: - if (e.IsSingleItem) + case NotifyCollectionChangedAction.Add: // Add or Insert + if (e.NewViewIndex == -1) { - // parent.CurrentFilter.IsMatch( - - var item = selector(e.NewItem); - - - - - if (e.NewStartingIndex != -1) - { - listView.Insert(e.NewStartingIndex, selector(e.NewItem)); - } - else // dict is -1 - { - listView.Add(selector(e.NewItem)); - } + listView.Add(e.NewView); } else { - if (e.NewStartingIndex != -1) - { - var array = ArrayPool.Shared.Rent(e.NewItems.Length); - try - { - var i = 0; - foreach (var item in e.NewItems) - { - array[i++] = selector(item); - } - - listView.InsertRange(e.NewStartingIndex, array.Take(e.NewItems.Length)); - } - finally - { - ArrayPool.Shared.Return(array, true); - } - } - else - { - foreach (var item in e.NewItems) - { - listView.Add(selector(item)); - } - } + listView.Insert(e.NewViewIndex, e.NewView); } break; - case NotifyCollectionChangedAction.Remove: + case NotifyCollectionChangedAction.Remove: // Remove + if (e.OldViewIndex == -1) // can't gurantee correct remove if index is not provided + { + listView.Remove(e.OldView); + } + else + { + listView.RemoveAt(e.OldViewIndex); + } break; - case NotifyCollectionChangedAction.Replace: + case NotifyCollectionChangedAction.Replace: // Indexer + if (e.NewViewIndex == -1) + { + } + else + { + listView[e.NewViewIndex] = e.NewView; + } + break; - case NotifyCollectionChangedAction.Move: + case NotifyCollectionChangedAction.Move: //Remove and Insert + if (e.NewViewIndex == -1) + { + } + else + { + listView.RemoveAt(e.OldViewIndex); + listView.Insert(e.NewViewIndex, e.NewView); + } break; - case NotifyCollectionChangedAction.Reset: + case NotifyCollectionChangedAction.Reset: // Clear break; default: break; @@ -89,6 +76,7 @@ namespace ObservableCollections.Internal // throw new NotImplementedException(); } + public TView this[int index] => throw new NotImplementedException(); public int Count => throw new NotImplementedException();