Exemple #1
0
        public void RegisterHandlers(IEnumerable <Type> handlerTypes)
        {
            foreach (var handlerType in handlerTypes)
            {
                foreach (var theInterface in handlerType.GetInterfaces())
                {
                    if (theInterface.IsGenericType && theInterface.GetGenericTypeDefinition() == typeof(IHandles <>))
                    {
                        var eventType     = theInterface.GetGenericArguments()[0];
                        var handlerMethod = new HandlerMethod(handlerType.GetMethod("Handle", new[] { eventType }));

                        if (_handleMethods.ContainsKey(eventType))
                        {
                            _handleMethods[eventType].Add(handlerMethod);
                        }
                        else
                        {
                            _handleMethods.Add(eventType, new List <HandlerMethod> {
                                handlerMethod
                            });
                        }
                    }
                }
            }
        }
Exemple #2
0
        public void RegisterHandlers(IEnumerable<Type> handlerTypes)
        {
            foreach (var handlerType in handlerTypes)
            {
                foreach (var theInterface in handlerType.GetInterfaces())
                {
                    if (theInterface.IsGenericType && theInterface.GetGenericTypeDefinition() == typeof(IHandles<>))
                    {
                        var eventType = theInterface.GetGenericArguments()[0];
                        var handlerMethod = new HandlerMethod(handlerType.GetMethod("Handle", new[] { eventType }));

                        if (_handleMethods.ContainsKey(eventType))
                        {
                            _handleMethods[eventType].Add(handlerMethod);
                        }
                        else
                        {
                            _handleMethods.Add(eventType, new List<HandlerMethod> { handlerMethod });
                        }
                    }
                }
            }
        }