Dotnet logo

.NET Tools

Essential productivity kit for .NET and game developers

How-To's

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:

screenshot_01.jpg

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.

screenshot_02.jpg

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

screenshot_03.jpg

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.

screenshot_04.jpg

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

image description