Esempio n. 1
0
        /// <summary>
        /// Adds the supplied handler to the collection of event handlers.
        /// </summary>
        /// <param name="handler">The handler to be added.</param>
        public void AddHandler(IEventHandlerValue handler)
        {
            IList <IEventHandlerValue> handlers;

            if (!EventHandlers.TryGetValue(handler.EventName, out handlers))
            {
                handlers = new List <IEventHandlerValue>();
                EventHandlers [handler.EventName] = handlers;
            }
            handlers.Add(handler);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds the supplied handler to the collection of event handlers.
        /// </summary>
        /// <param name="handler">The handler to be added.</param>
        public void AddHandler(IEventHandlerValue handler)
        {
            IList handlers = EventHandlers [handler.EventName] as IList;

            if (handlers == null)
            {
                handlers = new ArrayList();
                EventHandlers [handler.EventName] = handlers;
            }
            handlers.Add(handler);
        }
Esempio n. 3
0
        /// <summary>
        /// Adds the supplied handler to the collection of event handlers.
        /// </summary>
        /// <param name="handler">The handler to be added.</param>
        public void AddHandler(IEventHandlerValue handler)
        {
            _eventHandlers = _eventHandlers ?? new Dictionary <string, List <IEventHandlerValue> >();

            if (!_eventHandlers.TryGetValue(handler.EventName, out var handlers))
            {
                handlers = new List <IEventHandlerValue>();
                _eventHandlers[handler.EventName] = handlers;
            }

            handlers.Add(handler);
        }
            /// <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);
                }
            }
Esempio n. 5
0
 /// <summary>
 /// Adds the supplied handler to the collection of event handlers.
 /// </summary>
 /// <param name="handler">The handler to be added.</param>
 public void AddHandler(IEventHandlerValue handler)
 {
     IList handlers = EventHandlers [handler.EventName] as IList;
     if (handlers == null)
     {
         handlers = new ArrayList ();
         EventHandlers [handler.EventName] = handlers;
     }
     handlers.Add (handler);
 }
Esempio n. 6
0
        /// <summary>
        /// Adds the supplied handler to the collection of event handlers.
        /// </summary>
        /// <param name="handler">The handler to be added.</param>
        public void AddHandler (IEventHandlerValue handler)
        {
            IList<IEventHandlerValue> handlers;

            if (!EventHandlers.TryGetValue(handler.EventName, out handlers)) 
            {
                handlers = new List<IEventHandlerValue>();
                EventHandlers [handler.EventName] = handlers;
            }
            handlers.Add (handler);
        }