public SubscriptionToken Add <TEventType>(Action <TEventType> action) where TEventType : IEvent { var eventType = typeof(TEventType); WeakActionReference actionReference; lock (_eventTypesWithActions) { if (_eventTypesWithActions.All(i => i.EventType != eventType)) { _eventTypesWithActions.Add(new EventTypeWithActions(eventType)); } var actionTarget = action.Target; var actionMethod = action.Method; actionReference = new WeakActionReference(actionTarget, actionMethod); _eventTypesWithActions.Single(i => i.EventType == eventType).Actions.Add(actionReference); } return(new SubscriptionToken(eventType, actionReference)); }
internal SubscriptionToken(Type eventType, WeakActionReference actionReference) { EventType = eventType; ActionReference = actionReference; }