Coding Helpers – Auto Declare
Auto Declare allows you to quickly declare a variable (field, local or parameter) based on its type. To apply Auto Declare, type the class name and press the Ctrl+A shortcut. The variable will be declared with an appropriate name, and an action hint will be shown:
As you see, the identifier name is inherited from its type. The name of a variable is formatted according to your identifier code style settings. The style settings can be set for fields, local variables and parameters separately on the “Editor | Code Style | Identifiers” options page in the Options Dialog:
For example, the field of the StringBuilder type will be named _StringBuilder:
You can also specify the default names for identifiers of a certain class on the “Editor | Code Style | Default Names” options page:
The Enabled option specifies whether the default names are used by Auto Declare. If the option is turned off, the declared identifier inherits the name from its type. Otherwise, if the Enabled option is turned on, AutoDeclare will use default names from this options page.
To add or delete a default name for a specific type, use the New and Delete buttons appropriately. For example, let’s specify the default name for the StringBuilder type to be just an “sb”.
- Click on the Enabled checkbox if it is not checked
- Click on the New button
- Fill the TypaName field
- Fill the Value field
- Click the OK button or press the Enter key to save your changes:
Now, when we declare a local variable of the StringBuilder type, we will get the following result:
—– Products: CodeRush Pro Versions: 10.2 and up VS IDEs: any Updated: Feb/05/2011 ID: C065