ReSharper Help

Change Signature

ReSharper | Refactor | Change Signature…
Ctrl+F6
ReSharper_ChangeSignature

This refactoring combines several different modifications that can be made to signatures of methods, constructors, properties, and indexers. Along with changing the signature in the declaration, ReSharper finds and updates all usages, base symbols, implementations, and overrides of the modified symbol in the current solution.

In this topic:

Applicable modifications

Using this refactoring, you can perform the following modifications:

Modification / SymbolMethodPropertyConstructorIndexer
Change name feature_available feature_available feature_available
Change return type feature_available feature_available
Change names and types of parameters feature_available feature_available feature_available
Add or remove parameters feature_available feature_available feature_available
Reorder parameters feature_available feature_available feature_available

Invoking the refactoring with a command

To change signature of a function

  1. Place the caret at the declaration or a usage of a method, property, constructor, or indexer in the editor, or select it in the File Structure window.
  2. Do one of the following:
    • Press Ctrl+F6.
    • Press Ctrl+Shift+R and then choose Change Signature
    • Right-click and choose Refactor | Change Signature on the context menu.
    • Choose ReSharper | Refactor | Change Signature… in the main menu.
    The Change Signature dialog will open.
  3. Type a new name of the symbol in the Name field. If necessary, change the return type of the method in the Return type field.
  4. In the Parameters area, edit types, names, modifiers and default values of the existing parameters. If necessary, use the Add and Remove buttons to create or remove parameters. Click Move Up and Move Down to reorder parameters.
  5. If you do not want to change the usages of the function, ReSharper can leave the existing declaration and call it inside the new declaration, thus allowing to leave the existing usages unchanged. To do so, choose Delegate via overloading method in the Calls selector (see below for details).
  6. Check the new signature in the Signature preview field.
  7. To apply the refactoring, click Next.
  8. If you added parameters, ReSharper suggests you a several ways to fix calls of the function: you can choose to leave the code of the calls non-compilable, use 'null' or specific value for all calls, or use a call diagram to pick values for each specific call individually (see below for details).
  9. If no conflicts are found, ReSharper performs the refactoring immediately. Otherwise, it prompts you to resolve conflicts.
ReSharper Change Signature wizard

Changing signature without updating the calls

If you choose Delegate via overloading method in the Calls selector in the refactoring wizard, ReSharper leaves the existing declaration and calls it inside the new declaration, thus allowing to leave the existing usages unchanged.

Note that this option is not available if you modify a function form an inheritance hierarchy.

For example, if you changed the name and reordered parameters of a method public string Foo(string s, int x), ReSharper will create the following code for you:

Before refactoringUpdating callsWithout updating calls
public string Foo(string s, int x) { return String.Format("'{0}': {1} times", s, x); } public void Test() { Foo("test", 10); }
public string Bar(int x, string s) { return String.Format("'{0}': {1} times", s, x); } public void Test() { Bar(10, "test"); }
public string Foo(string s, int x) { return Bar(x, s); } public string Bar(int x, string s) { return String.Format("'{0}': {1} times", s, x); } public void Test() { Foo("test", 10); }

Performing the refactoring in-place

You can change function's signature by modifying its declaration right in the editor and then applying a quick-fix to invoke the solution-wide refactoring.

For instance, if you reorder parameters in a method, a grey border appears around the method signature, notifying you that the refactoring is available. You can press Alt+Enter to find the refactoring in the action list:

Applying the Change Signature refactoring inline
After applying the quick-fix, a dialog box shows your changes to the method signature:
Applying the Change Signature refactoring inline
You can click Next to apply the change solution-wide.

You can also apply the Change Signature refactoring when you add one new argument in any of the function's calls. In this case, ReSharper detects the incorrect call, highlights it and suggests the corresponding quick-fix:

Applying the Change Signature refactoring inline from a method usage
This quick-fix will invoke the refactoring and update the declaration of the function and all its usages solution-wide. If necessary, ReSharper will display a call diagram to pick values for each specific call individually

Updating calls with a call diagram (push/pull parameter tool)

If you are changing a function signature so that a new parameter is added, ReSharper provides several ways of updating function calls. Besides using 'null' or a constant value for all calls, you can update each individual call using visual representation of calls.

If you perform the refactoring with the wizard, select Resolve with call tree on the last page of the wizard and click Next. If you perform refactoring from a quick-fix on an updated function call, the tool window with all calls of the modified function opens automatically:

Change signature - updating calls with call diagram

Expand each call and check the available ways of acquiring values for the newly added parameter. Use the corresponding check boxes to select the desired way, or select User edit to edit the call manually.

Applicability in different languages

This feature is supported in the following languages/technologies:

C# VB.NET C++ HTML ASPX Razor JavaScript TypeScript CSS XML XAML RESX Build Scripts
feature_available feature_available feature_available

The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by Language section.

See Also

Last modified: 3 September 2015