Esempio n. 1
0
        private static IEnumerable <EventHandlerAttributeMethod> getEventHandlerMethods(Type eventHandlerType)
        {
            IEnumerable <MethodInfo> methods = eventHandlerType.GetRuntimeMethods().Where(m => m.CustomAttributes.Any(a => a.AttributeType == typeof(EventHandlerAttribute)));

            List <EventHandlerAttributeMethod> eventHandlerMethods = new List <EventHandlerAttributeMethod>(methods.Count());

            foreach (MethodInfo methodInfo in methods)
            {
                // Return methods marked with [EventHandler].
                eventHandlerMethods.Add(EventHandlerAttributeMethod.Create(methodInfo));
            }

            return(eventHandlerMethods);
        }
Esempio n. 2
0
        private void registerEventHandlerMethod <TAttributed, TEvent>(Func <TAttributed> attributedObjectFactory, EventHandlerAttributeMethod eventHandlerMethod)
            where TAttributed : class
            where TEvent : class, IEvent
        {
            Type eventType = typeof(TEvent);

            EventHandlerDelegate newHandleCommandDelegate = eventHandlerMethod.CreateDelegate <TAttributed, TEvent>(attributedObjectFactory);

            IList <EventHandlerDelegate> eventHandlerDelegates;

            if (!_eventHandlerDelegatesByEventType.TryGetValue(eventType, out eventHandlerDelegates))
            {
                eventHandlerDelegates = new List <EventHandlerDelegate>()
                {
                    newHandleCommandDelegate
                };

                _eventHandlerDelegatesByEventType.Add(eventType, eventHandlerDelegates);
            }
            else
            {
                eventHandlerDelegates.Add(newHandleCommandDelegate);
            }
        }