Change Signature refactoring
Refactor | Change Signature...
Ctrl0R,0V
This refactoring combines several modifications that can be made to signatures of methods, constructors, properties, and indexers. Along with changing signature in the declaration, JetBrains Rider finds and updates all usages, base symbols, implementations, and overrides of the modified symbol in the current solution.
tip
If you only need to change method name, use the Rename refactoring.
JetBrains Rider lets you change method signature in other ways (get rid of out parameters, wrap parameters in a tuple or in a new class, and so on) with the Transform Parameters refactoring.
Using this refactoring, you can perform the following modifications:
Modification / Symbol | Method | Property | Constructor | Indexer |
---|---|---|---|---|
Change name | ||||
Change return type | ||||
Change names and types of parameters | ||||
Add or remove parameters | ||||
Reorder parameters |
warning
Changing a return type or parameter type, or removing parameters may cause errors, which you will need to correct manually.
Place the caret at the declaration or a usage of a method, property, constructor, or indexer in the editor, or select it in the Structure window window.
Do one of the following:
Press Ctrl0R,0V.
Press AltEnter and choose Change Signature.
Press CtrlShift0R and then choose Change Signature.
Choose Refactor | Change Signature from the main menu.
The Change Signature dialog will open.
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.
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.
If you do not want to change the usages of the function, JetBrains Rider can leave the existing declaration and call it inside the new declaration, thus allowing you to leave the existing usages unchanged. To do so, choose Delegate via overloading method (for more information, refer to Change signature without updating the calls).
Check the new signature in the preview field.
To apply the refactoring, click Next.
If you added parameters, JetBrains Rider suggests 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 (for more information, refer to Updating calls with a call diagram (Push/Pull Parameter tool)).
If no conflicts are found, JetBrains Rider performs the refactoring immediately. Otherwise, it prompts you to resolve conflicts.
tip
Right after the refactoring has been completed, all changes that it makes anywhere, including other files, are registered as a single operation. So you can use the Undo action Ctrl0Z to roll back all these changes with a single keystroke.
note
If you changed type of some parameter or a return type to a type not available in the current namespace or to a type that can be resolved ambiguously, JetBrains Rider will suggest specifying a full name for the type.
![JetBrains Rider Change Signature wizard JetBrains Rider Change Signature wizard](https://resources.jetbrains.com/help/img/rider/2024.3/Refactorings__Change_Signature__dialog_box.png)
If you choose Delegate via overloading method in the refactoring wizard, JetBrains Rider leaves the existing declaration and calls it inside the new declaration, thus allowing you to leave the existing usages unchanged.
Note that this option is not available if you modify a function from an inheritance hierarchy.
For example, if you changed the name and reordered parameters of a method public string Foo(string s, int x)
, JetBrains Rider will create the following code for you:
Before refactoring
public string Foo(string s, int x){ return String.Format("'{0}': {1} times", s, x);}public void Test(){ Foo("test", 10);}
Refactor with updating calls
public string Bar(int x, string s){ return String.Format("'{0}': {1} times", s, x);}public void Test(){ Bar(10, "test");}
Before refactoring
public string Foo(string s, int x){ return String.Format("'{0}': {1} times", s, x);}public void Test(){ Foo("test", 10);}
Refactor without updating calls
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);}
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.
tip
To reorder parameters, place the caret at a parameter at function declaration or usage, press Ctrl+Alt+Shift and then use right and left arrows to change parameters' position. For more information, refer to Rearrange code elements.
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 AltEnter to find the refactoring in the action list:
![Applying the Change Signature refactoring inline Applying the Change Signature refactoring inline](https://resources.jetbrains.com/help/img/rider/2024.3/Refactorings__Inplace_Refactorings__change_signature_01.png)
After applying the quick-fix, a dialog shows your changes to the method signature:
![Applying the Change Signature refactoring inline Applying the Change Signature refactoring inline](https://resources.jetbrains.com/help/img/rider/2024.3/Refactorings__Inplace_Refactorings__change_signature_02.png)
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, JetBrains Rider detects the incorrect call, highlights it and suggests the corresponding quick-fix:
![Applying the Change Signature refactoring inline from a method usage Applying the Change Signature refactoring inline from a method usage](https://resources.jetbrains.com/help/img/rider/2024.3/Change_signature_inplace_03.png)
This quick-fix will invoke the refactoring and update the declaration of the function and all its usages solution-wide. If necessary, JetBrains Rider will display a call diagram to pick values for each specific call individually
tip
There are other refactorings that you can apply in-place.
If you are changing a function signature so that a new parameter is added, JetBrains Rider 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 Change signature - updating calls with call diagram](https://resources.jetbrains.com/help/img/rider/2024.3/change_signature_fix_usages.png)
In this view, you can check the affected calls and locate them in the editor with a click. For each call, select the desired way of acquiring values for the newly added parameter, or select User edit to edit the call manually.