Finding all methods that handle form events using NDepend
-
08-07-2019 - |
Question
I was wondering if someone would be able to help me write a CQL query for NDepend that will show me all the methods in my form class that handle the form events. So I would like to be able to find all the methods that look like this:
Private Sub AddFolderButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddFolderButton.Click
I have had a look through some of the options but I can't really find anything that does what I need.
I have only just started using NDepend, so I haven't really got used to it yet, but I do know one thing how the hell did I live without it all this time.
Solution
I am Patrick from the NDepend team and I confirm, so far using a condition 'Namelike + regular expression' on the 'method name + signature' is the best way to achieve what you want with CQL.
OTHER TIPS
I have sort of got something that works but its not really 100% correct, because all the form generated event handlers have an underscores in there name, I used the underscore as a filter, I also filter where the name has "EventArgs" in it. The query looks like this:
SELECT METHODS WHERE NameLike "_" OR NameLike "EventArgs" AND !IsSpecialName AND IsPrivate
That query pretty much returns all the methods that handle events but I would still like to find a more correct way.