Mark Levison

Musings on No Touch Deployment, .NET development and photography

<November 2008>
SuMoTuWeThFrSa
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456


Navigation

Other

Blogroll

Subscriptions

Post Categories



Monday, June 21, 2004 - Posts

Using reflection to get a list of event subscribers

Recently I wanted to test whether we were successfully releasing all our event subscriptions when an object was disposed. I thought this would be a simple task, use Type.GetEvents() to get the events and then use the resulting EventInfo's to get a list of subscribers. Not quite so simple, while EventInfo has methods to add and remove events, it has no invocation list. After a bit more work I discovered the trick is to ask for the events as fields and then cast the resulting object to Delegate. Now I can invoke GetInvocationList(). Too bad MS didn't include GetInvocationList() on the EventInfo. Problem solved: our unit tests are starting to get vey good at catching subscriber leaks.

posted Monday, June 21, 2004 9:35 AM by mlevison with 0 Comments




Powered by Dot Net Junkies, by Telligent Systems