Bestimmt die Anzahl der registrierten EventHandler eines beliebigen Events mittels Reflection
// using System.Reflection;
EventHandlerList events = (EventHandlerList)typeof(Component)
.GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Instance)
.GetValue(MyComboBox, null);
object key = typeof(ComboBox)
.GetField("EVENT_SELECTEDINDEXCHANGED", BindingFlags.NonPublic | BindingFlags.Static)
.GetValue(null);
Delegate handlers = events[key];
int numberOfEventHandlers = handlers.GetInvocationList().Length;
foreach (Delegate handler in handlers.GetInvocationList())
{
MethodInfo method = handler.Method;
string name = handler.Target == null ? "" : handler.Target.ToString();
if (handler.Target is Control) name = ((Control)handler.Target).Name;
Console.WriteLine(name + "; " + method.DeclaringType.Name + "." + method.Name);
}
Kommentare zum Snippet