From 97722fbe9d474adffbba0b92e9727c48a8205234 Mon Sep 17 00:00:00 2001 From: John T Date: Sat, 11 Nov 2017 08:53:55 -0500 Subject: Only 1/4 broken ShiftFS and WIP File Skimmer --- ShiftOS.Engine/Misc/EventList.cs | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 ShiftOS.Engine/Misc/EventList.cs (limited to 'ShiftOS.Engine/Misc/EventList.cs') diff --git a/ShiftOS.Engine/Misc/EventList.cs b/ShiftOS.Engine/Misc/EventList.cs new file mode 100644 index 0000000..e5202e7 --- /dev/null +++ b/ShiftOS.Engine/Misc/EventList.cs @@ -0,0 +1,71 @@ +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; } + } +} -- cgit v1.2.3