Skip to content

Commit

Permalink
#129 - Add support for registering IEventHandler<object> for getting …
Browse files Browse the repository at this point in the history
…all nofitications for all events in DefaultEventManager.
  • Loading branch information
maraf committed Jan 11, 2019
1 parent ba5c912 commit 5d8d928
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Neptuo.Events/Internals/ThreeBranchStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,27 @@ public void RemoveContextHandler(Type eventType, object handler)

#region Reading handlers

private IEnumerable<object> ConcatHandlers(List<object> concreteHandlers, List<object> genericHandlers)
{
if (concreteHandlers == null && genericHandlers == null)
return Enumerable.Empty<object>();

if (concreteHandlers == null)
return genericHandlers;

if (genericHandlers == null)
return concreteHandlers;

return Enumerable.Concat(concreteHandlers, genericHandlers);
}

private IEnumerable<object> GetHandlersInternal(Type eventType, Dictionary<Type, List<object>> storage, bool includeSubTypes)
{
if (storage != null)
{
List<object> 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<object>();
Expand Down

0 comments on commit 5d8d928

Please sign in to comment.