领胜LDS 键盘AOI检测项目
wells.liu
2020-07-04 65faad811883efc4264e3a5ca2c4e64340c198f5
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
 
namespace Bro.Common.Helper
{
    public class NoticedList<T> : List<T> where T : class
    {
        public Action<NotifyCollectionChangedAction> OnItemChanged;
 
        public Action<NotifyCollectionChangedAction, List<T>> OnItemChangedWithItemInfo;
 
        //public Action<NotifyCollectionChangedAction, NoticedList<T>> OnItemChangedWithSelf;
 
        public new T this[int index]
        {
            get
            {
                if (index >= 0 && index < Count)
                {
                    return base[index];
                }
                else
                {
                    return null;
                }
 
            }
            set
            {
                if (base[index] != value)
                {
                    base[index] = value;
                    OnItemChanged?.Invoke(NotifyCollectionChangedAction.Replace);
                    OnItemChangedWithItemInfo?.Invoke(NotifyCollectionChangedAction.Replace, new List<T>() { value });
                }
            }
        }
 
        public new void Add(T item)
        {
            base.Add(item);
            OnItemChanged?.Invoke(NotifyCollectionChangedAction.Add);
            OnItemChangedWithItemInfo?.Invoke(NotifyCollectionChangedAction.Add, new List<T>() { item });
        }
 
        public new void AddRange(IEnumerable<T> collection)
        {
            base.AddRange(collection);
            OnItemChanged?.Invoke(NotifyCollectionChangedAction.Add);
            OnItemChangedWithItemInfo?.Invoke(NotifyCollectionChangedAction.Add, collection.ToList());
        }
 
        public new void Clear()
        {
            base.Clear();
            OnItemChanged?.Invoke(NotifyCollectionChangedAction.Reset);
            OnItemChangedWithItemInfo?.Invoke(NotifyCollectionChangedAction.Reset, this);
        }
 
        public new void Insert(int index, T item)
        {
            base.Insert(index, item);
            OnItemChanged?.Invoke(NotifyCollectionChangedAction.Add);
            OnItemChangedWithItemInfo?.Invoke(NotifyCollectionChangedAction.Add, new List<T>() { item });
        }
 
        public new void InsertRange(int index, IEnumerable<T> collection)
        {
            base.InsertRange(index, collection);
            OnItemChanged?.Invoke(NotifyCollectionChangedAction.Add);
            OnItemChangedWithItemInfo?.Invoke(NotifyCollectionChangedAction.Add, collection.ToList());
        }
 
        public new bool Remove(T item)
        {
            bool flag = base.Remove(item);
 
            if (flag)
            {
                OnItemChanged?.Invoke(NotifyCollectionChangedAction.Remove);
                OnItemChangedWithItemInfo?.Invoke(NotifyCollectionChangedAction.Remove, new List<T>() { item });
            }
 
            return flag;
        }
 
        public new int RemoveAll(Predicate<T> match)
        {
            List<T> temp = this.Where(u => match.Invoke(u)).ToList();
            int i = base.RemoveAll(match);
            if (i > 0)
            {
                OnItemChanged?.Invoke(NotifyCollectionChangedAction.Remove);
                OnItemChangedWithItemInfo?.Invoke(NotifyCollectionChangedAction.Remove, temp);
            }
 
            return i;
        }
 
        public new void RemoveAt(int index)
        {
            var item = this[index];
            base.RemoveAt(index);
            OnItemChanged?.Invoke(NotifyCollectionChangedAction.Remove);
            OnItemChangedWithItemInfo?.Invoke(NotifyCollectionChangedAction.Remove, new List<T>() { item });
        }
 
        public new void RemoveRange(int index, int count)
        {
            List<T> temp = this.Skip(index).Take(count).ToList();
            base.RemoveRange(index, count);
            OnItemChanged?.Invoke(NotifyCollectionChangedAction.Remove);
            OnItemChangedWithItemInfo?.Invoke(NotifyCollectionChangedAction.Remove, temp);
        }
    }
}