Create an overloaded delegate quickly

Sometimes it is necessary to create method overloads that just pass default values to other overloads. ReSharper allows you to do this quickly and easily.

Take this simple method for example:


We need to take the CreateUser method and add a new parameter to it. However, we also need to keep the old CreateUser method signature around for other code that still uses that version of the method signature. Using ReSharper’s Change Signiture (Control-F6) feature will allow us to create an overloaded method to solve our problem.


When the Change Signature dialog opens for this method, we will go ahead and add our new email parameter to this method.


In the above screenshot, notice the option “Delegate via overloading method” circled in red. Clicking this box is what will take the signature changes and turn them into a new overloaded method.

When the changes are ready, clicking Next in the Change Signature dialog will now produce the following code.


Notice that in the SaveNewUser method, the original method signature remains intact, but it is now delegated through an overloaded method. The CreateUser method now has two overloaded variations, the delegating method and the main method, where we can now add code to handle the new email parameter.

Jeff Pennal
JetBrains .NET Evangelist

This entry was posted in How-To's and tagged . Bookmark the permalink.

4 Responses to Create an overloaded delegate quickly

  1. “Delegate” seems like a poor choice of works for something that generates .NET code but has nothing to do with a .NET delegate.

    “Create new CreateUser overload and call selected CreateUser” seems like it better describes what will happen without using the much overloaded word “delegate”.

  2. Yuriy says:

    What about creating overloaded metod by removing a parameter and calling old versions with default parameter value?

    Last R# 4 builds create overload n wrong direction (as for me).

  3. Simon says:

    If I have a Func is there a shortcut that allows me to “extract delegate type” to somthing like

    *in MyDelegate.cs*
    public delegate Stuff MyDelegate();


Leave a Reply

Your email address will not be published. Required fields are marked *