1: internal void HookUpAutomaticHandlers()
2: {
3: if (this.SupportAutoEvents)
4: {
5: object obj2 = _eventListCache[base.GetType()];
6: IDictionary dictionary = null;
7: if (obj2 == null)
8: {
9: lock (_lockObject)
10: {
11: obj2 = _eventListCache[base.GetType()];
12: if (obj2 == null)
13: {
14: dictionary = new ListDictionary();
15: this.GetDelegateInformation(dictionary);
16: if (dictionary.Count == 0)
17: {
18: obj2 = _emptyEventSingleton;
19: }
20: else
21: {
22: obj2 = dictionary;
23: }
24: _eventListCache[base.GetType()] = obj2;
25: }
26: }
27: }
28: if (obj2 != _emptyEventSingleton)
29: {
30: dictionary = (IDictionary) obj2;
31: foreach (string str in dictionary.Keys)
32: {
33: EventMethodInfo info = (EventMethodInfo) dictionary[str];
34: bool flag = false;
35: MethodInfo methodInfo = info.MethodInfo;
36: Delegate delegate2 = base.Events[_eventObjects[str]];
37: if (delegate2 != null)
38: {
39: foreach (Delegate delegate3 in delegate2.GetInvocationList())
40: {
41: if (delegate3.Method.Equals(methodInfo))
42: {
43: flag = true;
44: break;
45: }
46: }
47: }
48: if (!flag)
49: {
50: IntPtr functionPointer = methodInfo.MethodHandle.GetFunctionPointer();
51: EventHandler handler = new CalliEventHandlerDelegateProxy(this, functionPointer, info.IsArgless).Handler;
52: base.Events.AddHandler(_eventObjects[str], handler);
53: }
54: }
55: }
56: }
57: }
58:
59: private void GetDelegateInformation(IDictionary dictionary)
60: {
61: if (HttpRuntime.IsFullTrust)
62: {
63: this.GetDelegateInformationWithNoAssert(dictionary);
64: }
65: else
66: {
67: this.GetDelegateInformationWithAssert(dictionary);
68: }
69: }
70:
71: private void GetDelegateInformationWithNoAssert(IDictionary dictionary)
72: {
73: if (this is Page)
74: {
75: this.GetDelegateInformationFromMethod("Page_PreInit", dictionary);
76: this.GetDelegateInformationFromMethod("Page_PreLoad", dictionary);
77: this.GetDelegateInformationFromMethod("Page_LoadComplete", dictionary);
78: this.GetDelegateInformationFromMethod("Page_PreRenderComplete", dictionary);
79: this.GetDelegateInformationFromMethod("Page_InitComplete", dictionary);
80: this.GetDelegateInformationFromMethod("Page_SaveStateComplete", dictionary);
81: }
82: this.GetDelegateInformationFromMethod("Page_Init", dictionary);
83: this.GetDelegateInformationFromMethod("Page_Load", dictionary);
84: this.GetDelegateInformationFromMethod("Page_DataBind", dictionary);
85: this.GetDelegateInformationFromMethod("Page_PreRender", dictionary);
86: this.GetDelegateInformationFromMethod("Page_Unload", dictionary);
87: this.GetDelegateInformationFromMethod("Page_Error", dictionary);
88: if (!this.GetDelegateInformationFromMethod("Page_AbortTransaction", dictionary))
89: {
90: this.GetDelegateInformationFromMethod("OnTransactionAbort", dictionary);
91: }
92: if (!this.GetDelegateInformationFromMethod("Page_CommitTransaction", dictionary))
93: {
94: this.GetDelegateInformationFromMethod("OnTransactionCommit", dictionary);
95: }
96: }
97:
98: private bool GetDelegateInformationFromMethod(string methodName, IDictionary dictionary)
99: {
100: EventHandler handler = (EventHandler) Delegate.CreateDelegate(typeof(EventHandler), this, methodName, true, false);
101: if (handler != null)
102: {
103: dictionary[methodName] = new EventMethodInfo(handler.Method, false);
104: return true;
105: }
106: VoidMethod method = (VoidMethod) Delegate.CreateDelegate(typeof(VoidMethod), this, methodName, true, false);
107: if (method != null)
108: {
109: dictionary[methodName] = new EventMethodInfo(method.Method, true);
110: return true;
111: }
112: return false;
113: }