using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Bro.Common.Helper { public class NoticedList : List where T : class { public Action OnItemChanged; public Action> OnItemChangedWithItemInfo; public Action> OnItemChangedWithSelf; public new T this[int index] { get { if (index >= 0 && index < this.Count) { return base[index]; } else { return null; } } set { if (base[index] != value) { base[index] = value; OnItemChanged?.Invoke(); OnItemChangedWithItemInfo?.Invoke(new List() { value }); OnItemChangedWithSelf?.Invoke(this); } } } public new void Add(T item) { base.Add(item); OnItemChanged?.Invoke(); OnItemChangedWithItemInfo?.Invoke(new List() { item }); OnItemChangedWithSelf?.Invoke(this); } public new void AddRange(IEnumerable collection) { base.AddRange(collection); OnItemChanged?.Invoke(); OnItemChangedWithItemInfo?.Invoke(collection.ToList()); OnItemChangedWithSelf?.Invoke(this); } public new void Clear() { base.Clear(); OnItemChanged?.Invoke(); OnItemChangedWithSelf?.Invoke(this); } public new void Insert(int index, T item) { base.Insert(index, item); OnItemChanged?.Invoke(); OnItemChangedWithItemInfo?.Invoke(new List() { item }); OnItemChangedWithSelf?.Invoke(this); } public new void InsertRange(int index, IEnumerable collection) { base.InsertRange(index, collection); OnItemChanged?.Invoke(); OnItemChangedWithItemInfo?.Invoke(collection.ToList()); OnItemChangedWithSelf?.Invoke(this); } public new bool Remove(T item) { bool flag = base.Remove(item); if (flag) { OnItemChanged?.Invoke(); OnItemChangedWithItemInfo?.Invoke(new List() { item }); OnItemChangedWithSelf?.Invoke(this); } return flag; } public new int RemoveAll(Predicate match) { int i = base.RemoveAll(match); if (i > 0) { OnItemChanged?.Invoke(); OnItemChangedWithSelf?.Invoke(this); } return i; } public new void RemoveAt(int index) { base.RemoveAt(index); OnItemChanged?.Invoke(); OnItemChangedWithSelf?.Invoke(this); } public new void RemoveRange(int index, int count) { base.RemoveRange(index, count); OnItemChanged?.Invoke(); OnItemChangedWithSelf?.Invoke(this); } } }