System.Web.HttpApplicationFactory.AddHandler C# (CSharp) Method

AddHandler() private method

private AddHandler ( EventInfo evt, object target, System.Web.HttpApplication app, MethodInfo method ) : void
evt System.Reflection.EventInfo
target object
app System.Web.HttpApplication
method System.Reflection.MethodInfo
return void
		void AddHandler (EventInfo evt, object target, HttpApplication app, MethodInfo method)
		{
			int length = method.GetParameters ().Length;

			if (length == 0) {
				NoParamsInvoker npi = new NoParamsInvoker (app, method);
				evt.AddEventHandler (target, npi.FakeDelegate);
			} else {
				if (method.IsStatic) {
					evt.AddEventHandler (target, Delegate.CreateDelegate (
						evt.EventHandlerType, method));
				} else {
					evt.AddEventHandler (target, Delegate.CreateDelegate (
								     evt.EventHandlerType, app,
								     method));
				}
			}
			
		}

Usage Example

Example #1
0
        internal static void AttachEvents(HttpApplication app)
        {
            HttpApplicationFactory factory = theFactory;
            Hashtable possibleEvents       = factory.GetApplicationTypeEvents(app);

            foreach (string key in possibleEvents.Keys)
            {
                int    pos        = key.IndexOf('_');
                string moduleName = key.Substring(0, pos);
                object target;
                if (moduleName == "Application")
                {
                    target = app;
                }
                else
                {
                    target = app.Modules [moduleName];
                    if (target == null)
                    {
                        continue;
                    }
                }

                string    eventName = key.Substring(pos + 1);
                EventInfo evt       = target.GetType().GetEvent(eventName);
                if (evt == null)
                {
                    continue;
                }

                string usualName  = moduleName + "_" + eventName;
                object methodData = possibleEvents [usualName];
                if (methodData == null)
                {
                    continue;
                }

                if (eventName == "End" && moduleName == "Session")
                {
                    Interlocked.CompareExchange(ref factory.session_end, methodData, null);
                    continue;
                }

                if (methodData is MethodInfo)
                {
                    factory.AddHandler(evt, target, app, (MethodInfo)methodData);
                    continue;
                }

                ArrayList list = (ArrayList)methodData;
                foreach (MethodInfo method in list)
                {
                    factory.AddHandler(evt, target, app, method);
                }
            }
        }