BlackWaspTM

This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

Refactoring
VS 2005+

Visual Studio Remove Parameters Command

As you refactor and redesign your classes, you may decide that you no longer require one or more parameters of a method. To delete parameters and ensure that calls to the method remain functional, you can use Visual Studio's Remove Parameters command.

Remove Parameters Command

When your classes must be updated to incorporate changes to requirements, you may decide that you wish to remove one or more parameters from an existing method. If the method is widely used, a change to its signature may require a significant number of changes, as every call to the method will need to be updated accordingly.

Visual Studio's Remove Parameters command helps with this type of refactoring operation. Rather than modify the method and all references to it manually, the command allows you to specify which of the parameters are no longer required. The method signature is updated and every call to the method that exists within the current solution is modified too. This means that, in most cases, the code will still compile correctly.

If a parameter that is removed from the method's signature is used within the method, the project will no longer build correctly. In this case, you must remove the code that uses the absent parameter or create and initialise a local variable with the same name within the class member.

To access the command, simply right-click the method that is to be modified. From the context-sensitive menu that appears, select "Refactor", then choose Remove Parameters.

Visual Studio Remove Parameters Menu Option

Once the command is selected, a dialog box will be displayed. The dialog box lists the existing parameters and allows you to select and remove those that are no longer required.

22 February 2009