PowerShell Studio: Rename Refactoring
- Written by David Corrales
- Last Updated: 22 April 2016
- Created: 01 May 2014
- Hits: 6858
Rename refactoring allows you to intelligently rename variables, controls, parameters, functions and more.
You start by right-clicking on the object you wish to rename to bring up the context menu. Then select Rename… from the menu:
You are then presented with the rename dialog:
Let us cover each field:
Here you enter the new name for the selected object.
This field lets you know what type of object you are renaming.
The field will display the following types:
|Event||Updates the event variable and references in the designer.|
|Function||Updates function declaration and function calls.|
|GUI Control||Updates the GUI control variables and updates any event names and return variables for projects.|
|Parameter||Updates the parameter for the function and any calls using the parameter.|
|Variable||Updates variables within the document that aren’t a parameter or GUI control.|
Note: Depending on the object’s type the some settings may vary.
The scope lets you define in which scope the objects will be replaced.
Depending on the object type the following scopes may be selected:
|Current Scope||Rename refactoring only occurs within the scope of the current function or event block.|
|Current Document||Rename refactoring will occur for all instances of the object within the current document.|
|Entire Project||Rename refactoring will occur for all instances of the object within all the project files.|
GUI Controls, Events, Parameters and Functions will always apply to the global scope such as the Current Document or the Entire Project.
Preview references changes:
When this option is checked, you will be presented with a dialog listing all the changes that will take affect.
Here you can preview the changes by clicking on any item in the list.
You can also uncheck an item if you do not want that particular instance to be modified.
Note: You are unable to uncheck items if you are renaming a GUI Control.
Rename Refactoring in Projects
Rename refactoring can be extremely useful when dealing with multiple files as in a project, because it will update all the project files (with the exception of excluded files):
In PowerShell Studio return variables are updated when a GUI control is renamed. In addition, when you rename a project file in PowerShell Studio, all the reference functions and return variables are updated to reflect the new file name.
If you include ps1 files as content and dot source the file within a project, calls to functions defined in the dot sourced file can be updated using rename refactoring.
The rename refactoring feature can be a big time saver when renaming events, variables, functions and other objects. In addition, with the preview you can quickly see where the object is used and selectively decide if you want to go forward with any change.