public override void Add(SelfAccumulateableEventArgs e) { var other = e as NamedObjectCollectionChangedEventArgs; if (other == null) { throw new ArgumentOutOfRangeException("Argument e should be of type NamedObjectCollectionEventArgs"); } if (!object.ReferenceEquals(_item, other._item)) { throw new ArgumentOutOfRangeException("Argument e has an item which is not identical to this item. This should not happen since Equals and GetHashCode are overriden."); } // MultipleChanges overrrides everything if (_operation.HasFlag(NamedObjectCollectionChangeType.MultipleChanges)) { return; } if (other._operation.HasFlag(NamedObjectCollectionChangeType.MultipleChanges)) { _operation = NamedObjectCollectionChangeType.MultipleChanges; _item = MultipleChangesItem; _newItemName = null; _oldItemName = null; return; } // Normal changes _newItemName = other._newItemName; _operation |= other._operation; if (other._operation.HasFlag(NamedObjectCollectionChangeType.ItemAdded)) { _operation = _operation.WithClearedFlag(NamedObjectCollectionChangeType.ItemRemoved); if (_oldItemName != _newItemName) { _operation = _operation.WithSetFlag(NamedObjectCollectionChangeType.ItemRenamed); } } else if (other._operation.HasFlag(NamedObjectCollectionChangeType.ItemRemoved)) { _operation = _operation.WithClearedFlag(NamedObjectCollectionChangeType.ItemAdded); _operation = _operation.WithClearedFlag(NamedObjectCollectionChangeType.ItemRenamed); } }
public override void Add(SelfAccumulateableEventArgs e) { var other = e as NamedObjectCollectionChangedEventArgs; if (other == null) throw new ArgumentOutOfRangeException("Argument e should be of type NamedObjectCollectionEventArgs"); if (!object.ReferenceEquals(this._item, other._item)) throw new ArgumentOutOfRangeException("Argument e has an item which is not identical to this item. This should not happen since Equals and GetHashCode are overriden."); // MultipleChanges overrrides everything if (this._operation.HasFlag(NamedObjectCollectionChangeType.MultipleChanges)) return; if (other._operation.HasFlag(NamedObjectCollectionChangeType.MultipleChanges)) { this._operation = NamedObjectCollectionChangeType.MultipleChanges; this._item = MultipleChangesItem; this._newItemName = null; this._oldItemName = null; return; } // Normal changes this._newItemName = other._newItemName; this._operation |= other._operation; if (other._operation.HasFlag(NamedObjectCollectionChangeType.ItemAdded)) { this._operation = this._operation.WithClearedFlag(NamedObjectCollectionChangeType.ItemRemoved); if (_oldItemName != _newItemName) this._operation = this._operation.WithSetFlag(NamedObjectCollectionChangeType.ItemRenamed); } else if (other._operation.HasFlag(NamedObjectCollectionChangeType.ItemRemoved)) { this._operation = this._operation.WithClearedFlag(NamedObjectCollectionChangeType.ItemAdded); this._operation = this._operation.WithClearedFlag(NamedObjectCollectionChangeType.ItemRenamed); } }