Over a million developers have joined DZone.

How to Determine Event Subscriptions at Runtime


Forgot this again, so thought I'd repost it...



Executing that in the immediate window will spawn you out a list of the attached event handlers to your event at runtime.

Also, if you're trying extract the invocation list of a dotNetBar ButtonItem control's click handler, then the following code is necessary due to the obsfucation of the code that dotNetBar controls have within them. The strange Convert.ToChar(2694) is required in order to ensure that the code page of the C# file remains as ANSI (or Windows 1252), instead of asking you to switch to UTF-8 if you use the actual character code that the private event is stored as.

var buttonItem = sender as ButtonItem;
            var clickHandler = string.Empty;
            if (buttonItem != null)

                var clickEvent = typeof(BaseItem).GetField(Convert.ToChar(2694).ToString(CultureInfo.InvariantCulture), BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);

                if (clickEvent != null)
                    var clickEventDelegate = clickEvent.GetValue(buttonItem) as Delegate;
                    if (clickEventDelegate != null)
                        var invocationList = clickEventDelegate.GetInvocationList();
                        if (invocationList.Length > 0)
                            clickHandler = invocationList[0].Method.Name;

                    "The click event {0} is yet to be implemented. If you're attached the debugger will now launch",
                    clickHandler), "Click event handler not yet implemented yet", MessageBoxButtons.OK, MessageBoxIcon.Information);

Published at DZone with permission of Merrick Chaffer, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}