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

GetApplicationTypeEvents() private method

private GetApplicationTypeEvents ( Type type ) : Hashtable
type System.Type
return System.Collections.Hashtable
		Hashtable GetApplicationTypeEvents (Type type)
		{
			if (have_app_events)
				return app_event_handlers;

			lock (this_lock) {
				if (app_event_handlers != null)
					return app_event_handlers;

				app_event_handlers = new Hashtable ();
				ArrayList methods = GetMethodsDeep (type);
				Hashtable used = null;
				MethodInfo m;
				string mname;
				
				foreach (object o in methods) {
					m = o as MethodInfo;
					if (m.DeclaringType != typeof (HttpApplication) && IsEventHandler (m)) {
						mname = m.ToString ();
						if (used == null)
							used = new Hashtable ();
						else if (used.ContainsKey (mname))
							continue;
						used.Add (mname, m);
						AddEvent (m, app_event_handlers);
					}
				}
				used = null;
				have_app_events = true;
			}

			return app_event_handlers;
		}

Same methods

HttpApplicationFactory::GetApplicationTypeEvents ( System.Web.HttpApplication app ) : Hashtable

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);
                }
            }
        }