internal void WireupAutomaticEvents() { if (!SupportAutoEvents || !AutoEventWireup) { return; } /* Avoid expensive reflection operations by computing the event info only once */ Type type = GetType(); ArrayList events = auto_event_info.InsertOrGet((uint)type.GetHashCode(), type, null, CollectAutomaticEventInfo); for (int i = 0; i < events.Count; ++i) { EvtInfo evinfo = (EvtInfo)events [i]; if (evinfo.noParams) { NoParamsInvoker npi = new NoParamsInvoker(this, evinfo.method); evinfo.evt.AddEventHandler(this, npi.FakeDelegate); } else { evinfo.evt.AddEventHandler(this, Delegate.CreateDelegate(typeof(EventHandler), this, evinfo.method)); } } }
internal void WireupAutomaticEvents() { if (!SupportAutoEvents || !AutoEventWireup) { return; } ArrayList events = null; /* Avoid expensive reflection operations by computing the event info only once */ lock (auto_event_info_monitor) { if (auto_event_info == null) { auto_event_info = new Hashtable(); } events = (ArrayList)auto_event_info [GetType()]; if (events == null) { events = CollectAutomaticEventInfo(); auto_event_info [GetType()] = events; } } for (int i = 0; i < events.Count; ++i) { EvtInfo evinfo = (EvtInfo)events [i]; if (evinfo.noParams) { NoParamsInvoker npi = new NoParamsInvoker(this, evinfo.method); evinfo.evt.AddEventHandler(this, npi.FakeDelegate); } else { evinfo.evt.AddEventHandler(this, Delegate.CreateDelegate( #if NET_2_0 typeof(EventHandler), this, evinfo.method)); #else typeof(EventHandler), this, evinfo.methodName)); #endif } } }
ArrayList CollectAutomaticEventInfo () { ArrayList events = new ArrayList (); foreach (string methodName in methodNames) { MethodInfo method = null; Type type; for (type = GetType (); type.Assembly != _System_Web_Assembly; type = type.BaseType) { method = type.GetMethod (methodName, bflags); if (method != null) break; } 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; } EvtInfo evinfo = new EvtInfo (); evinfo.method = method; evinfo.methodName = methodName; evinfo.evt = evt; evinfo.noParams = noParams; events.Add (evinfo); } return events; }
ArrayList CollectAutomaticEventInfo() { ArrayList events = new ArrayList(); foreach (string methodName in methodNames) { MethodInfo method = null; Type type; for (type = GetType(); type.Assembly != _System_Web_Assembly; type = type.BaseType) { method = type.GetMethod(methodName, bflags); if (method != null) { break; } } 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; } EvtInfo evinfo = new EvtInfo(); evinfo.method = method; evinfo.methodName = methodName; evinfo.evt = evt; evinfo.noParams = noParams; events.Add(evinfo); } return(events); }