Changing a Method's Signature

See Also

The Change Method Parameters command enables you to alter the signature of a method and have those changes propagated in all of the code that calls this method. Specifically, you can:

To add a parameter to a method:

  1. Right-click the method in the Source Editor and choose Refactor > Change Method Parameters from the contextual menu.

    The Change Method Parameters dialog box opens.

  2. Click the Add button to add a parameter.
  3. In the Parameters table, modify the name and type of the parameter that you have added. Then add a default value for the parameter in the Value column. You need to double-click a cell to make it editable.
  4. If you click Refactor, the IDE applies the changes automatically and skips the remaining steps. If you click Preview, the Refactoring window displays the lines of code that will be changed. Review the list and clear the checkbox of any code that you do not want changed. If the class that you are pushing members from has multiple subclasses and you do not want the members to be pushed to all of them, be sure to clear the checkboxes for the corresponding subclasses. Click Do Refactoring to apply the selected changes.

To reorder a parameter in a method signature:

  1. Right-click the method in the Source Editor and choose Refactor > Change Method Parameters from the contextual menu.
  2. Select a parameter that you want to move and click Move Up or Move Down to change its position in the list.
  3. Click Next. If you click Refactor, the IDE applies the changes automatically and skips the remaining steps.
  4. The Refactoring window displays the lines of code that will be changed. Review the list and clear the checkbox of any code that you do not want changed.
  5. Click Do Refactoring to apply the selected changes.

To change a method's access modifier:

  1. Right-click the method in the Source Editor and choose Refactor > Change Method Parameters from the contextual menu.
  2. Choose a modifier from the Visibility Modifier combo box.
  3. If you click Refactor, the IDE applies the changes automatically and skips the remaining steps. If you click Preview, the Refactoring window displays the lines of code that will be changed. Review the list and clear the checkbox of any code that you do not want changed. If the class that you are pushing members from has multiple subclasses and you do not want the members to be pushed to all of them, be sure to clear the checkboxes for the corresponding subclasses. Click Do Refactoring to apply the selected changes.
See Also
Refactoring: Quick Reference
Moving a Class Member to a Superclass
Moving a Class Member to a Subclass
Extracting a Method
Renaming a Field or Method
Undoing Refactoring Changes

Legal Notices