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, #if NET_2_0 method #else method.Name #endif )); } } }
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)); } } }
internal void WireupAutomaticEvents () { if (!SupportAutoEvents || !AutoEventWireup) return; Type type = GetType (); foreach (string methodName in methodNames) { MethodInfo method = type.GetMethod (methodName, bflags); if (method == null) continue; if (method.DeclaringType != type) { if (!method.IsPublic && !method.IsFamilyOrAssembly && !method.IsFamilyAndAssembly && !method.IsFamily) continue; } if (method.ReturnType != typeof (void)) continue; ParameterInfo [] parms = method.GetParameters (); int length = parms.Length; bool noParams = (length == 0); if (!noParams && (length != 2 || parms [0].ParameterType != typeof (object) || parms [1].ParameterType != typeof (EventArgs))) continue; int pos = methodName.IndexOf ("_"); string eventName = methodName.Substring (pos + 1); EventInfo evt = type.GetEvent (eventName); if (evt == null) { /* This should never happen */ continue; } if (noParams) { NoParamsInvoker npi = new NoParamsInvoker (this, methodName); evt.AddEventHandler (this, npi.FakeDelegate); } else { evt.AddEventHandler (this, Delegate.CreateDelegate ( typeof (EventHandler), this, methodName)); } } }