Beispiel #1
0
        /// <summary>
        /// Removes the specified object from the RelatedObjectList.
        /// </summary>
        /// <param name="item">The object to remove from the RelatedObjectList.</param>
        /// <returns></returns>
        public bool Remove(TypeProjection item)
        {
            if (IsReadOnly)
            {
                throw new InvalidOperationException("Cannot remove from a read-only list.");
            }

            if (item == null)
            {
                throw new ArgumentNullException("Cannot remove a null value on a RelatedObjectList.");
            }

            if (!IsOfType(typeof(T), item.GetType()))
            {
                throw new InvalidOperationException("This RelatedObjectList only supports removing objects of type " + typeof(T).Name);
            }

            foreach (ExpandoObject obj in ProjectionList)
            {
                if (AreProjectionsEqual(obj, item.CurrentObject))
                {
                    bool success = ProjectionList.Remove(obj);

                    if (success)
                    {
                        Owner.IsDirty = true;
                    }

                    return(success);
                }
            }

            return(false);
        }