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);
        }
Beispiel #2
0
        /// <summary>
        /// Inserts an object into the RelatedObjectList at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index at which an object should be inserted.</param>
        /// <param name="item">The object to insert. Duplicates will be ignored.</param>
        public void Insert(int index, TypeProjection item)
        {
            if (IsReadOnly)
            {
                throw new InvalidOperationException("Cannot insert into a read-only list.");
            }

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

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

            if (!Contains(item))
            {
                ProjectionList.Insert(index, item.CurrentObject);
                Owner.IsDirty = true;
            }
        }