예제 #1
0
        public static ComponentRegistration <TComponent> ListensToEvent <TComponent>(
            this ComponentRegistration <TComponent> registration,
            Type eventType,
            MethodInfo handleMethod
            ) where TComponent : class
        {
            Debug.Assert(handleMethod != null);
            Debug.Assert(handleMethod.ReturnType == typeof(void));
            Debug.Assert(handleMethod.GetParameters().Single().ParameterType == eventType);

            var /*Action<TListener, TEvent>*/ @delegate = (Delegate)(typeof(ComponentRegistrationEx).
                                                                     GetMethod("CreateInvoker", BindingFlags.Static | BindingFlags.NonPublic).
                                                                     MakeGenericMethod(typeof(TComponent), eventType).
                                                                     Invoke(null, new object[] { handleMethod })
                                                                     );

            registration.ExtendedProperties(Property.
                                            ForKey(GrayMatterFacility.CreateExtendedPropertyKey(
                                                       eventType, handleMethod.ReflectedType.ToString(),
                                                       handleMethod.Name
                                                       )).
                                            Eq(new Wiring(eventType, @delegate))
                                            );

            return(registration);
        }
예제 #2
0
        public ComponentRegistration <TListener> With(Action <TListener, TEvent> handler)
        {
            _componentRegistration.ExtendedProperties(Property.
                                                      ForKey(GrayMatterFacility.CreateExtendedPropertyKey(typeof(TEvent), null, null)).
                                                      Eq(new Wiring(typeof(TEvent), handler))
                                                      );

            return(_componentRegistration);
        }