From 5d8d9289ba64f04d9808b376b8874964a8255fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 11 Jan 2019 18:35:41 +0100 Subject: [PATCH] #129 - Add support for registering IEventHandler for getting all nofitications for all events in DefaultEventManager. --- .../Internals/ThreeBranchStorage.cs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Neptuo.Events/Internals/ThreeBranchStorage.cs b/src/Neptuo.Events/Internals/ThreeBranchStorage.cs index d4593196..6153d534 100644 --- a/src/Neptuo.Events/Internals/ThreeBranchStorage.cs +++ b/src/Neptuo.Events/Internals/ThreeBranchStorage.cs @@ -80,13 +80,27 @@ public void RemoveContextHandler(Type eventType, object handler) #region Reading handlers + private IEnumerable ConcatHandlers(List concreteHandlers, List genericHandlers) + { + if (concreteHandlers == null && genericHandlers == null) + return Enumerable.Empty(); + + if (concreteHandlers == null) + return genericHandlers; + + if (genericHandlers == null) + return concreteHandlers; + + return Enumerable.Concat(concreteHandlers, genericHandlers); + } + private IEnumerable GetHandlersInternal(Type eventType, Dictionary> storage, bool includeSubTypes) { if (storage != null) { - List handlers; - if (storage.TryGetValue(eventType, out handlers)) - return handlers; + storage.TryGetValue(eventType, out var concreteHandlers); + storage.TryGetValue(typeof(object), out var genericHandlers); + return ConcatHandlers(concreteHandlers, genericHandlers); } return Enumerable.Empty();