This problem happened originally when dynamicaly consuming Cat.NET's guis (outside VisualStudio) and there were a couple controls (like a ListView) that hooked event handlers that triggered functions that had DTE dependencies (which triggered an exception since we were running Cat.NET outside visualstudio (and the DTE2 object was null).
There doesn't seem to be an easy way to do this (and google didn't find a good solution) so using O2's powerful reflection APIs I was able to find a solution which is now available as these extensionmethods:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//for a UserControl (in fact any control that implements System.ComponentModel.Component) | |
var userControl = new UserControl(); | |
//we can get the current mapped event handlers | |
userControl.eventHandlers(); | |
//its signature | |
userControl.eventHandlers_MethodSignatures(); | |
//remove one by using the static field name | |
userControl.remove_EventHandler("EVENT_SELECTEDINDEXCHANGED"); | |
//or use this one specifically mapped to the SelectedIndexChanged event | |
userControl.remove_Event_SelectedIndexChanged |
Here is a document that shows how these extension methods were created: