/// <summary> /// Wires up the supplied event to any handler methods that match the event /// signature. /// </summary> /// <param name="theEvent">The event being wired up.</param> private void WireEvent(EventInfo theEvent) { // grab some info (such as the delegate's method signature) about the event DelegateInfo eventDelegate = new DelegateInfo(theEvent); // if the method name needs to be customised on a per event basis, do so string customMethodName = GetMethodNameCustomisedForEvent(theEvent.Name); // create the criteria for the handler method search... ComposedCriteria methodCriteria = new ComposedCriteria(); // a candidate handlers method name must match the custom method name methodCriteria.Add(new RegularExpressionMethodNameCriteria(customMethodName)); // the return Type of a candidate handlers method must be the same as the return type of the event methodCriteria.Add(new MethodReturnTypeCriteria(eventDelegate.GetReturnType())); // a candidate handlers method parameters must match the event's parameters methodCriteria.Add(new MethodParametersCriteria(eventDelegate.GetParameterTypes())); // and grab the methods that satisfy the criteria... BindingFlags methodFlags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public; MemberInfo[] methods = HandlerType.FindMembers( MemberTypes.Method, methodFlags, new MemberFilter(new CriteriaMemberFilter().FilterMemberByCriteria), methodCriteria); // and for each method that satisfied the criteria... foreach (MethodInfo method in methods) { #region Instrumentation if (log.IsDebugEnabled) { log.Debug(string.Format( CultureInfo.InvariantCulture, "Wiring up this method '{0}' to this event '{1}'", method.Name, theEvent.Name)); } #endregion IEventHandlerValue myHandler = method.IsStatic ? (IEventHandlerValue) new StaticEventHandlerValue() : (IEventHandlerValue) new InstanceEventHandlerValue(); myHandler.EventName = theEvent.Name; myHandler.MethodName = method.Name; myHandler.Wire(Source, Handler); } }