using System; using System.Collections.Generic; using System.Linq; namespace ShiftOS.Engine.Misc { [Serializable] public class EventList : List { public event EventHandler> ItemAdded; public event EventHandler> ItemRemoved; public new void Add(T obj) { base.Add(obj); ItemAdded?.Invoke(this, new EventListArgs(obj)); } public new void AddRange(IEnumerable objs) { foreach (var obj in objs) { base.Add(obj); ItemAdded?.Invoke(this, new EventListArgs(obj)); } } public new bool Remove(T obj) { var b = base.Remove(obj); ItemRemoved?.Invoke(this, new EventListArgs(obj)); return b; } public new void RemoveAt(int index) { base.RemoveAt(index); ItemRemoved?.Invoke(this, new EventListArgs(default)); } public new void RemoveAll(Predicate match) { //will this work foreach (var item in this.Where(match as Func ?? throw new InvalidOperationException())) { Remove(item); } } public new void RemoveRange(int start, int end) { for (var i = start; i <= end; i++) { Remove(this[i]); } } public new void Clear() { RemoveAll(x => true); } } public class EventListArgs : EventArgs { public EventListArgs(T item) => Item = item; public T Item { get; } } }