I have a method that was declared like this:
public ButtonObject CreateStandardButton(type1 arg1, type2 arg2,
ItemClickEventHandler eventHandler, type3 arg3, type4 arg4)
ItemClickEventHandler has the usual (sender, e) arguments. However, we never ended up using the (sender, e) arguments, so we have a bunch of calls like this:
myButton = CreateStandardButton(myArg1, myArg2,
(sender, e) => MyButtonClick(), myArg3, myArg4);
and, because this project was upgraded to .NET 3.5 about 15% of the way through, many calls like this:
myButton = CreateStandardButton(myArg1, myArg2,
delegate { MyButtonClick(); }, myArg3, myArg4);
We call this method a lot, so it's really annoying to have to add the lambda for unused arguments over and over. Therefore, I want to change all usages to this overload:
public ButtonObject CreateStandardButton(type1 arg1, type2 arg2,
Action eventHandler, type3 arg3, type4 arg4)
Which allows us to do this instead:
myButton = CreateStandardButton(myArg1, myArg2,
MyButtonClick, myArg3, myArg4);
The problem is that the usages of the old delegate syntax would require a cast to (Action)
because they're ambiguous to the compiler. So, in order to remove the annoyance, I want to do a find and replace, presumably with regular expressions.
What's the regular expression to do this?