Ejemplo n.º 1
0
 protected void OnAdded(object sender, EventListEventArgs <T> e)
 {
     lock (EventLock)
     {
         if (Added != null)
         {
             Added(this, e);
         }
     }
 }
Ejemplo n.º 2
0
 protected void OnRemoving(object sender, EventListEventArgs <T> e)
 {
     lock (EventLock)
     {
         if (Removing != null)
         {
             Removing(this, e);
         }
     }
 }
Ejemplo n.º 3
0
 protected void OnClearing(object sender, EventListEventArgs <T> e)
 {
     lock (EventLock)
     {
         if (Clearing != null)
         {
             Clearing(this, e);
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Removes all elements from the ExtendedList(Of T).
        /// </summary>
        public virtual void Clear()
        {
            // Clearing event
            EventListEventArgs <T> e = new EventListEventArgs <T>();

            OnClearing(this, e);
            if (e.Cancel)
            {
                return;
            }
            // Clear
            _List.Clear();
            // Cleared event
            OnCleared(this, EventArgs.Empty);
        }
Ejemplo n.º 5
0
        //Public Shadows Sub RemoveRange(items As IEnumerable(Of T)) '
        //If items Is Nothing OrElse items.Count = 0 Then Return
        //Dim itemList As ICollection(Of T) = items.ToList()
        //' Removing event
        //Dim e As New ExtendedListEventArgs(Of T)(itemList)
        //RaiseEvent Removing(Me, e)
        //If e.Cancel Then Return
        //' RemoveRange
        //MyBase.RemoveRange(itemList)
        //' Removed event
        //RaiseEvent Removed(Me, e)
        //End Sub

        /// <summary>
        /// Removes the element at the specified index of the ExtendedList(Of T).
        /// </summary>
        /// <param name="index"></param>
        public virtual void RemoveAt(int index)
        {
            T item = this[index];
            // Removing event
            EventListEventArgs <T> e = new EventListEventArgs <T>(item);

            OnRemoving(this, e);
            if (e.Cancel)
            {
                return;
            }
            // RemoveAt
            _List.RemoveAt(index);
            // Removed event
            OnRemoved(this, e);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Inserts an element into the ExtendedList(Of T) at the specified index.
        /// </summary>
        /// <param name="index"></param>
        /// <param name="item"></param>
        public virtual void Insert(int index, T item)
        {
            if (item == null)
            {
                return;
            }
            // Adding event
            EventListEventArgs <T> e = new EventListEventArgs <T>(item, index);

            OnAdding(this, e);
            if (e.Cancel)
            {
                return;
            }
            // Insert
            _List.Insert(index, item);
            // Added event
            OnAdded(this, e);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds an object to the end of the ExtendedList(Of T).
        /// </summary>
        /// <param name="item"></param>
        public virtual void Add(T item)
        {
            if (item == null)
            {
                return;
            }
            // Adding event
            EventListEventArgs <T> e = new EventListEventArgs <T>(item);

            OnAdding(this, e);
            if (e.Cancel)
            {
                return;
            }
            // Add
            _List.Add(item);
            // Added event
            OnAdded(this, e);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Removes a range of elements from the ExtendedList(Of T).
        /// </summary>
        /// <param name="index"></param>
        /// <param name="count"></param>
        public virtual void RemoveRange(int index, int count)
        {
            if (count <= 0)
            {
                return;
            }
            EventList <T> itemList = _List.GetRange(index, count);
            // Removing event
            EventListEventArgs <T> e = new EventListEventArgs <T>(itemList);

            OnRemoving(this, e);
            if (e.Cancel)
            {
                return;
            }
            // RemoveRange
            _List.RemoveRange(index, count);
            // Removed event
            OnRemoved(this, e);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Inserts the elements of a collection into the ExtendedList(Of T) at the specified index
        /// </summary>
        /// <param name="index"></param>
        /// <param name="items"></param>
        public virtual void InsertRange(int index, IEnumerable <T> items)
        {
            if (items == null || !items.Any())
            {
                return;
            }
            EventList <T> itemList = items.ToList();
            // Adding event
            EventListEventArgs <T> e = new EventListEventArgs <T>(itemList, index);

            OnAdding(this, e);
            if (e.Cancel)
            {
                return;
            }
            // AddRange
            _List.InsertRange(index, itemList);
            // Added event
            OnAdded(this, e);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Removes the first occurrence of a specific object from the ExtendedList(Of T).
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public virtual bool Remove(T item)
        {
            bool functionReturnValue = false;

            if (item == null || IndexOf(item) < 0)
            {
                return(false);
            }
            // Removing event
            EventListEventArgs <T> e = new EventListEventArgs <T>(item);

            OnRemoving(this, e);
            if (e.Cancel)
            {
                return(false);
            }
            // Remove
            functionReturnValue = _List.Remove(item);
            // Removed event
            OnRemoved(this, e);
            return(functionReturnValue);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Removes all the elements that match the conditions defined by the specified predicate.
        /// </summary>
        /// <param name="match"></param>
        /// <returns></returns>
        public virtual int RemoveAll(Predicate <T> match)
        {
            EventList <T> items = _List.FindAll(match);

            if (items.Count == 0)
            {
                return(0);
            }
            // Removing event
            EventListEventArgs <T> e = new EventListEventArgs <T>(items);

            OnRemoving(this, e);
            if (e.Cancel)
            {
                return(0);
            }
            // RemoveAll (modified)
            var result = _List.RemoveAll(it => items.Contains(it));

            // Removed event
            OnRemoved(this, e);
            return(result);
        }