Going through our codebase, many of our custom controls have a DetachEvents
method that gets called with the control is being disposed. Quite frequently, other developers incorrectly are the event handler
private void DetachEvents()
{
myControl.Click += new EventHandler(myControl_Click);
}
When it should, of course, be -=
instead of +=
.
I'm trying to come up with a regex for the Find & Replace tool in Visual Studios to only find me DetachEvent
methods that contain the +=
but I cannot figure out how to. I'll be here all day if I just keep Finding every occurance of DetachEvents()
I tried: DetachEvents()[.]+=[.]
thinking the period would find anything before and after the +=
but it doesn't find anything.
Try escaping the
+
:But this will match any instance of
+=
which followsDetatchEvents()
. You might want to use[^}]
instead of.
, assuming you don't have any other code blocks inside theDetachEvents
method: