Пример #1
0
        /// <summary>
        ///     Determines whether an entity is in the set.
        /// </summary>
        /// <returns>
        ///     <c>true</c> if <paramref name="item"/> is found in the set; otherwise, false.
        /// </returns>
        /// <param name="item"> The entity to locate in the set. The value can be null.</param>
        public new virtual bool Contains(TEntity item)
        {
            IEqualityComparer <TEntity> comparer = new ObjectReferenceEqualityComparer();

            foreach (var entity in Items)
            {
                if (comparer.Equals(entity, item))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
        /// <summary>
        ///     Removes the first occurrence of a specific entity object from the set.
        /// </summary>
        /// <returns>
        ///     <c>true</c> if <paramref name="item"/> is successfully removed; otherwise, false.
        ///     This method also returns <c>false</c> if <paramref name="item"/> was not found in the set.
        /// </returns>
        /// <param name="item"> The entity to remove from the set. The value can be null.</param>
        public new virtual bool Remove(TEntity item)
        {
            IEqualityComparer <TEntity> comparer = new ObjectReferenceEqualityComparer();

            var index = 0;

            for (; index < Count; index++)
            {
                if (comparer.Equals(Items[index], item))
                {
                    break;
                }
            }

            if (index == Count)
            {
                return(false);
            }

            RemoveItem(index);
            return(true);
        }