예제 #1
0
        private bool ReadEventHandlersFromHandlerList(FieldAccesor eventKeyAccesor)
        {
            if ( !eventKeyAccesor.IsValid )
                return false;

            if (eventListeners == null)
            {
                eventListeners = new ArrayList();
            }

            eventKeyAccesor.Save();
            object eventKey = eventKeyAccesor.Value;
            if (eventKey == null)
            {	// no data
                return true;
            }

            eventHandlerList = eventDescriptor.EventHandlerList;
            if (eventHandlerList != null)
            {
                object entry = GetHead();
                if (entry != null)
                {
                    do
                    {
                        // first read the target
                        if (keyAccesor == null)
                        {
                            keyAccesor = new FieldAccesor(entry, "key");
                        }
                        keyAccesor.Target = entry;
                        keyAccesor.Save();
                        if (keyAccesor.Value == eventKey)
                        {
                            if (handlerAccesor == null)
                            {
                                handlerAccesor = new FieldAccesor(entry, "handler");
                            }

                            handlerAccesor.Target = entry;
                            handlerAccesor.Save();

                            if (handlerAccesor.Value != null)
                            {
                                eventListeners.Add(new EventListenerPropertyDescriptor(eventDescriptor, handlerAccesor.Value as Delegate));
                            }
                        }
                        entry = GetListEntry(entry);
                    } while (entry != null);
                }
            }
            return true;
        }
예제 #2
0
        internal void ReadListeners()
        {
            // for examples we use event with name "Load"
            // first try to read key representing the static eventKey (EventLoad as key object static)
            FieldAccesor eventKeyAccesor = new FieldAccesor(eventDescriptor.Component, "Event" + eventDescriptor.Name);
            if (ReadEventHandlersFromHandlerList(eventKeyAccesor))
            {	// there is a key like "Event" + event name ("eg: EventLoad") representing the key in the eventHandlerList
                return;
            }
            if( eventDescriptor.Name.EndsWith("Changed") )
            {	// try "EventBackColor" for "BackColorChanged" event
                string shortName = eventDescriptor.Name.Substring(0, eventDescriptor.Name.IndexOf("Changed") );
                eventKeyAccesor = new FieldAccesor(eventDescriptor.Component, "Event" + shortName);
                if (ReadEventHandlersFromHandlerList(eventKeyAccesor))
                {	// there is a key like "Event" + event name ("eg: EventLoad") representing the key in the eventHandlerList
                    return;
                }
            }
            eventKeyAccesor = new FieldAccesor(eventDescriptor.Component, "EVENT_" + eventDescriptor.Name);
            if (ReadEventHandlersFromHandlerList(eventKeyAccesor))
            {	// there is a key like "Event" + event name ("eg: EventLoad") representing the key in the eventHandlerList
                return;
            }

            // try to read the delegate on the object directly!
            // try "Load"
            FieldAccesor delegateDirectAccesor = new FieldAccesor(eventDescriptor.Component, eventDescriptor.Name);
            if (!delegateDirectAccesor.IsValid)
            { // try "onLoadDelegate"
                delegateDirectAccesor = new FieldAccesor(eventDescriptor.Component, "on" + eventDescriptor.Name + "Delegate");
            }
            if (!delegateDirectAccesor.IsValid)
            { // try "onLoad"
                delegateDirectAccesor = new FieldAccesor(eventDescriptor.Component, "on" + eventDescriptor.Name);
            }

            if (delegateDirectAccesor.IsValid)
            {
                delegateDirectAccesor.Save();
                Delegate eventHandlers = delegateDirectAccesor.Value as Delegate;
                if (eventHandlers != null)
                {
                    eventListeners = new ArrayList();
                    Delegate[] invocationList = eventHandlers.GetInvocationList();
                    foreach (Delegate del in invocationList)
                    {
                        eventListeners.Add(new EventListenerPropertyDescriptor(eventDescriptor, del));
                    }
                }
            }
            else
            { // sorry - give up - don't know how to read the implementation of this event :(
            }
        }