Procházet zdrojové kódy

* ReflectionEventDescriptor.cs: Bind handlers to the actual event so that
the delegates get invoked when the methods are.


svn path=/trunk/mcs/; revision=41388

Jackson Harper před 21 roky
rodič
revize
dde7ceca57

+ 5 - 0
mcs/class/System/System.ComponentModel/ChangeLog

@@ -1,3 +1,8 @@
+2005-03-02  Jackson Harper  <[email protected]>
+
+	* ReflectionEventDescriptor.cs: Bind handlers to the actual event so that
+	the delegates get invoked when the methods are.
+
 2005-03-02  Jackson Harper  <[email protected]>
 
 	* EventDescriptorCollection.cs: Handle null in the constructor properly.

+ 18 - 21
mcs/class/System/System.ComponentModel/ReflectionEventDescriptor.cs

@@ -4,9 +4,8 @@
 // Authors:
 //  Lluis Sanchez Gual ([email protected])
 //
-// (C) Novell, Inc. 2004
+// (C) Novell, Inc. 2004, 2005
 //
-
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -37,28 +36,41 @@ namespace System.ComponentModel
 {
 	internal class ReflectionEventDescriptor: EventDescriptor
 	{
-		Hashtable handlers;
 		Type _eventType;
 		Type _componentType;
 		EventInfo _eventInfo;
-		
+
+		MethodInfo add_method;
+		MethodInfo remove_method;
+
 		public ReflectionEventDescriptor (EventInfo eventInfo) : base (eventInfo.Name, (Attribute[]) eventInfo.GetCustomAttributes (true))
 		{
 			_eventInfo = eventInfo;
 			_componentType = eventInfo.DeclaringType;
 			_eventType = eventInfo.EventHandlerType;
+
+			add_method = eventInfo.GetAddMethod ();
+			remove_method = eventInfo.GetRemoveMethod ();
 		}
 
 		public ReflectionEventDescriptor (Type componentType, EventDescriptor oldEventDescriptor, Attribute[] attrs) : base (oldEventDescriptor, attrs)
 		{
 			_componentType = componentType;
 			_eventType = oldEventDescriptor.EventType;
+
+			EventInfo event_info = componentType.GetEvent (oldEventDescriptor.Name);
+			add_method = event_info.GetAddMethod ();
+			remove_method = event_info.GetRemoveMethod ();
 		}
 
 		public ReflectionEventDescriptor (Type componentType, string name, Type type, Attribute[] attrs) : base (name, attrs)
 		{
 			_componentType = componentType;
 			_eventType = type;
+
+			EventInfo event_info = componentType.GetEvent (name);
+			add_method = event_info.GetAddMethod ();
+			remove_method = event_info.GetRemoveMethod ();
 		}
 		
 		EventInfo GetEventInfo ()
@@ -73,27 +85,12 @@ namespace System.ComponentModel
 
 		public override void AddEventHandler (object component, System.Delegate value)
 		{
-			if (handlers == null)
-				handlers = new Hashtable ();
-			
-			ArrayList delegates = (ArrayList) handlers [component];
-			if (delegates == null) {
-				delegates = new ArrayList ();
-				handlers [component] = delegates;
-			}
-			
-			if (!delegates.Contains (value))
-				delegates.Add (value);
+			add_method.Invoke (component, new object [] { value });
 		}
 
 		public override void RemoveEventHandler (object component, System.Delegate value)
 		{
-			if (handlers == null) return;
-			
-			ArrayList delegates = (ArrayList) handlers [component];
-			if (delegates == null) return;
-			
-			delegates.Remove (value);
+			remove_method.Invoke (component, new object [] { value });
 		}
 
 		public override System.Type ComponentType