aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Engine/Misc/EventList.cs
diff options
context:
space:
mode:
authorJohn T <[email protected]>2017-11-11 08:53:55 -0500
committerJohn T <[email protected]>2017-11-11 08:53:55 -0500
commit97722fbe9d474adffbba0b92e9727c48a8205234 (patch)
tree65dfe45bbfd194ddb534cc80107ab8e6d80cf5bc /ShiftOS.Engine/Misc/EventList.cs
parenta10440a45c40652b13e883aec832a0c8ded685e8 (diff)
downloadshiftos-rewind-97722fbe9d474adffbba0b92e9727c48a8205234.tar.gz
shiftos-rewind-97722fbe9d474adffbba0b92e9727c48a8205234.tar.bz2
shiftos-rewind-97722fbe9d474adffbba0b92e9727c48a8205234.zip
Only 1/4 broken ShiftFS and WIP File Skimmer
Diffstat (limited to 'ShiftOS.Engine/Misc/EventList.cs')
-rw-r--r--ShiftOS.Engine/Misc/EventList.cs71
1 files changed, 71 insertions, 0 deletions
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<T> : List<T>
+ {
+ public event EventHandler<EventListArgs<T>> ItemAdded;
+ public event EventHandler<EventListArgs<T>> ItemRemoved;
+
+ public new void Add(T obj)
+ {
+ base.Add(obj);
+ ItemAdded?.Invoke(this, new EventListArgs<T>(obj));
+ }
+
+ public new void AddRange(IEnumerable<T> objs)
+ {
+ foreach (var obj in objs)
+ {
+ base.Add(obj);
+ ItemAdded?.Invoke(this, new EventListArgs<T>(obj));
+ }
+ }
+
+ public new bool Remove(T obj)
+ {
+ var b = base.Remove(obj);
+
+ ItemRemoved?.Invoke(this, new EventListArgs<T>(obj));
+ return b;
+ }
+
+ public new void RemoveAt(int index)
+ {
+ base.RemoveAt(index);
+ ItemRemoved?.Invoke(this, new EventListArgs<T>(default));
+ }
+
+ public new void RemoveAll(Predicate<T> match)
+ {
+ //will this work
+ foreach (var item in this.Where(match as Func<T, bool> ?? 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<T> : EventArgs
+ {
+ public EventListArgs(T item) => Item = item;
+
+ public T Item { get; }
+ }
+}