Exemplo n.º 1
0
            private void UpdateAncestors(NotifyCollectionChangedEventArgs eventArgs)
            {
                switch (eventArgs.Action)
                {
                case NotifyCollectionChangedAction.Add:
                    CheckIndexValid(eventArgs.NewStartingIndex, "NewStartingIndex", NotifyCollectionChangedAction.Add);
                    Ancestors.Insert(eventArgs.NewStartingIndex, CreateSubscriberForCollectionItem(eventArgs.NewItems.Cast <object>().Single()));
                    return;

                case NotifyCollectionChangedAction.Remove:
                    CheckIndexValid(eventArgs.OldStartingIndex, "OldStartingIndex", NotifyCollectionChangedAction.Remove);
                    Ancestors[eventArgs.OldStartingIndex].Dispose();
                    Ancestors.RemoveAt(eventArgs.OldStartingIndex);
                    return;

                case NotifyCollectionChangedAction.Replace:
                    CheckIndexValid(eventArgs.OldStartingIndex, "OldStartingIndex", NotifyCollectionChangedAction.Replace);
                    Ancestors[eventArgs.OldStartingIndex].Dispose();
                    Ancestors[eventArgs.OldStartingIndex] = CreateSubscriberForCollectionItem(eventArgs.NewItems.Cast <object>().Single());
                    return;

                case NotifyCollectionChangedAction.Move:
                    CheckIndexValid(eventArgs.OldStartingIndex, "OldStartingIndex", NotifyCollectionChangedAction.Move);
                    CheckIndexValid(eventArgs.NewStartingIndex, "NewStartingIndex", NotifyCollectionChangedAction.Move);
                    var movingAncestor = Ancestors[eventArgs.OldStartingIndex];
                    Ancestors.RemoveAt(eventArgs.OldStartingIndex);
                    Ancestors.Insert(eventArgs.NewStartingIndex, movingAncestor);
                    return;

                case NotifyCollectionChangedAction.Reset:
                    DisposeAndClearAncestors();
                    foreach (var ancestor in InitAncestors(EffectiveObject))
                    {
                        Ancestors.Add(ancestor);
                    }
                    return;

                default:
                    throw new ArgumentException(string.Format("Unknown eventArgs.Action enum action: {0}", eventArgs.Action), "eventArgs");
                }
            }