tangxu
2025-01-13 4f7cb65b079d88d5a829688b24d26d5145c5df47
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
namespace DPumpHydr.WinFrmUI.WenSkin
{
    public class WenList<T> : List<T>
    {
        public event EventHandler<WenListEventArgs<T>> ItemAdded;
        public event EventHandler<WenListEventArgs<T>> ItemRemoved;
        protected virtual void OnItemAdded(T e, int index)
        {
            ItemAdded?.Invoke(this, new WenListEventArgs<T>(e, index));
        }
        protected virtual void OnItemRemoved(T e, int index)
        {
            ItemRemoved?.Invoke(this, new WenListEventArgs<T>(e, index));
        }
        public new void Add(T item)
        {
            base.Add(item);
            OnItemAdded(item, base.Count - 1);
        }
        public new void AddRange(IEnumerable<T> collection)
        {
            foreach (var item in collection)
            {
                Add(item);
            }
        }
        public new bool Remove(T item)
        {
            int index = base.IndexOf(item);
            OnItemRemoved(item, index);
            return base.Remove(item);
        }
        public new void RemoveAt(int index)
        {
            T t = base[index];
            OnItemRemoved(t, index);
            base.RemoveAt(index);
        }
    }
 
    public class WenListEventArgs<T> : EventArgs
    {
        public WenListEventArgs(T item, int index)
        {
            this.Item = item;
            this.Index = index;
        }
 
        public int Index { get; set; }
 
        public T Item { get; set; }
    }
 
}