Removing an object from the list

Oct 14, 2009 at 6:24 PM

I've had the need to remove an object from an objectset without actually adding it to the RemovedList. Back when we purchased OPF3 I did a simple modification to allow this. I'd love if you guys could implement it. Here's the code that I wrote into ObjectSet_1.cs. Basically the exact same as the remove methods, except it doesn't add the object to the RemovedList.

        /// <summary>
        /// Removes the object at the specified index from the <see cref="Opf3.ObjectSet{T}">ObjectSet</see>. 
        /// </summary>
        /// <param name="index">The zero-based index of the item to move.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">Index is less than zero or index is equal to
        /// or greater than <see cref="ObjectSet{T}.Count">Count</see>.</exception>
        public void RemoveObjectFromList(int index)
        {
            lock (this)
            {
                T obj = this[index];
                _list.RemoveAt(index);

                // Un hook the event that is fired when a property of the item changes.
                if (_raiseItemChangedEvents)
                    UnHookPropertyChanged(obj as INotifyPropertyChanged);

                // Invoked the event to notify the user that the list has been changed.
                OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, index));
            }
		}

		/// <summary>
		/// Removes the object at the specified index from the <see cref="Opf3.ObjectSet{T}">ObjectSet</see>. 
		/// </summary>
		/// <param name="item">The object to remove from the <see cref="Opf3.ObjectSet{T}">ObjectSet</see>.</param>
		/// <exception cref="System.ArgumentOutOfRangeException">Index is less than zero or index is equal to
		/// or greater than <see cref="ObjectSet{T}.Count">Count</see>.</exception>
		public bool RemoveObjectFromList( T item )
		{
			int index = -1;
			lock ( this )
			{
				// Get the index of the item.
				index = _list.IndexOf( item );
			}

			if ( index == -1 )
			{
				Tracing.Current.TraceWarning( "Could not remove object. Item not found." );
				return false;
			}

			// Remove the item.
			this.RemoveObjectFromList( index );
			return true;
		}