/// <summary>
        /// Returns all items of a given <see cref="DomainObjectCollection"/> that are not part of another <see cref="DomainObjectCollection"/>. The
        /// comparison is made by <see cref="DomainObject.ID"/>, not by reference.
        /// </summary>
        /// <param name="collection">The collection to return items from.</param>
        /// <param name="exceptedDomainObjects">A collection containing items that should not be returned.</param>
        /// <returns>
        /// An enumeration of all items from <paramref name="collection"/> that are not part of <paramref name="exceptedDomainObjects"/>.
        /// </returns>
        /// <remarks>
        ///     <para>The method does not modify the given <see cref="DomainObjectCollection"/> istances.</para>
        /// </remarks>
        public static IEnumerable <DomainObject> GetItemsExcept(this DomainObjectCollection collection, HashSet <DomainObject> exceptedDomainObjects)
        {
            ArgumentUtility.CheckNotNull("collection", collection);
            ArgumentUtility.CheckNotNull("exceptedDomainObjects", exceptedDomainObjects);

            return(collection.Cast <DomainObject>().Where(domainObject => !exceptedDomainObjects.Contains(domainObject)));
        }
        /// <summary>
        /// Checks whether a <see cref="DomainObjectCollection"/> matches a sequence of <see cref="DomainObject"/> items by reference.
        /// The comparison takes the order of elements into account.
        /// </summary>
        /// <param name="collection">The <see cref="DomainObjectCollection"/> to check.</param>
        /// <param name="comparedSequence">The sequence of elements to check against.</param>
        /// <returns><see langword="true"/> if the collection contains the same items as the comparedCollection in the same order; otherwise, <see langword="false"/>.</returns>
        public static bool SequenceEqual(this DomainObjectCollection collection, IEnumerable <DomainObject> comparedSequence)
        {
            ArgumentUtility.CheckNotNull("collection", collection);
            ArgumentUtility.CheckNotNull("comparedSequence", comparedSequence);

            return(collection.Cast <DomainObject> ().SequenceEqual(comparedSequence));
        }
        /// <summary>
        /// Adds all items of the given <see cref="DomainObjectCollection"/> to the <see cref="DomainObjectCollection"/>, that are not already part of it.
        /// This method is a convenience method combining <see cref="DomainObjectCollection.Contains"/> and <see cref="DomainObjectCollection.AddRange"/>. If there are no changes made to this
        /// collection, the <see cref="DomainObjectCollection"/> method does not touch the associated end point (if any).
        /// </summary>
        /// <param name="collection">The collection to add items to.</param>
        /// <param name="sourceCollection">The collection to add items from. Must not be <see langword="null"/>.</param>
        /// <remarks>
        /// <para>
        /// To check if an item is already part of the <see cref="DomainObject.ID"/> its <see cref="DomainObject"/> is used.
        /// <see cref="DomainObject.ID"/> does not check if the item references are identical. In case the two <see cref="DomainObject"/> contain
        /// different items with the same <see cref="DomainObjectCollection"/>, <see cref="System"/> will thus ignore those items.
        /// </para>
        /// <para>
        /// This method calls <see cref="DomainObjectCollection.AddRange"/> and might throw any of the exceptions that can be thrown by
        /// <see cref="DomainObjectCollection.AddRange"/>-
        /// </para>
        /// </remarks>
        public static void UnionWith(this DomainObjectCollection collection, DomainObjectCollection sourceCollection)
        {
            ArgumentUtility.CheckNotNull("collection", collection);
            ArgumentUtility.CheckNotNull("sourceCollection", sourceCollection);

            collection.CheckNotReadOnly("A read-only collection cannot be combined with another collection.");

            collection.AddRange(sourceCollection.Cast <DomainObject> ().Where(obj => !collection.Contains(obj.ID)));
        }
 public IEnumerator <T> GetEnumerator()
 {
     return(_wrappedData.Cast <T>().GetEnumerator());
 }
Example #5
0
 public IEnumerator <T> GetEnumerator()
 {
     return(_wrappedCollection.Cast <T> ().GetEnumerator());
 }