/// <summary> /// Removes a <see cref="DomainObject"/> from the collection. /// </summary> /// <param name="id">The <see cref="ObjectID"/> of the <see cref="DomainObject"/> to remove. Must not be <see langword="null"/>.</param> /// <exception cref="System.ArgumentNullException"><paramref name="id"/> is <see langword="null"/>.</exception> /// <exception cref="System.NotSupportedException">The collection is read-only.</exception> public void Remove(ObjectID id) { ArgumentUtility.CheckNotNull("id", id); this.CheckNotReadOnly("Cannot remove an item from a read-only collection."); _dataStrategy.Remove(id); }
/// <summary> /// Unregisters the item with the given <paramref name="objectID"/> as an original item of this collection. This means the item is removed from /// the <see cref="OriginalData"/> collection, and it is also removed from this <see cref="ChangeCachingCollectionDataDecorator"/> collection. If /// the <see cref="OriginalData"/> collection does not contain the item, an exception is thrown. If this collection does not contain the item, it /// is only removed from the <see cref="OriginalData"/>. This operation may invalidate the state cache. /// </summary> /// <param name="objectID">The <see cref="ObjectID"/> of the <see cref="DomainObject"/> to be unregistered.</param> public void UnregisterOriginalItem(ObjectID objectID) { ArgumentUtility.CheckNotNull("objectID", objectID); // Original collection must contain this item if (!_originalData.ContainsObjectID(objectID)) { var message = string.Format("The original collection does not contain a domain object with ID '{0}'.", objectID); throw new InvalidOperationException(message); } // Check if this collection contains the item if (ContainsObjectID(objectID)) { // Standard case: Both collections contain the item; the item is removed from both. // Remove the item from the unobserved inner collection to avoid copy on write: if the contents hasn't been copied, we want to modify both // collections at the same time! // This way, if the original collection has not yet been copied, it will automatically not contain the item and the state cache remains valid. _unobservedWrappedData.Remove(objectID); // If the original collection has already been copied, we must remove the item manually and invalidate the state cache: Collections previously // different because the item was in different places might now be the same. if (_originalData.IsContentsCopied) { _originalData.Remove(objectID); OnChangeStateUnclear(); } } else { // Special case: The current collection does not contain the item // We must remove the item from the original collection only and raise a potential state change notification _originalData.Remove(objectID); OnChangeStateUnclear(); } }
public virtual bool Remove(DomainObject domainObject) { ArgumentUtility.CheckNotNull("domainObject", domainObject); return(_wrappedData.Remove(domainObject)); }