From 5754de141d42c8a72c2679ebaeb8da4788a02061 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 3 Apr 2015 16:28:04 +0100 Subject: [PATCH] Add Remove support to TypeDictionary. --- OpenRA.Game/Primitives/TypeDictionary.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/OpenRA.Game/Primitives/TypeDictionary.cs b/OpenRA.Game/Primitives/TypeDictionary.cs index bc41195ac4..e4bbf0c656 100644 --- a/OpenRA.Game/Primitives/TypeDictionary.cs +++ b/OpenRA.Game/Primitives/TypeDictionary.cs @@ -91,6 +91,27 @@ namespace OpenRA.Primitives return new T[0]; } + public void Remove(T val) + { + var t = val.GetType(); + + foreach (var i in t.GetInterfaces()) + InnerRemove(i, val); + foreach (var tt in t.BaseTypes()) + InnerRemove(tt, val); + } + + void InnerRemove(Type t, object val) + { + List objs; + object obj; + + if (dataMultiple.TryGetValue(t, out objs)) + objs.Remove(val); + else if (dataSingular.TryGetValue(t, out obj)) + dataSingular.Remove(t); + } + public IEnumerator GetEnumerator() { return WithInterface().GetEnumerator();