ReSharper lets you define naming rules for different symbols including but not limited to types, namespaces, interfaces, parameters, method properties and events, static fields, instance fields etc.
When you have a naming rule in force, ReSharper:
- Keeps your specific naming guidelines in mind when it provides
code completion options,generates new members, and expandstemplates . - Displays warnings when it detects members that don't comply with your naming style (in C# code):
For every kind of symbol, you can configure casing options, prefixes and suffixes, variations for different access rights, abbreviations to preserve, and other options.
Regarding language coverage, you can configure:
-
Common naming style settings by choosing ReSharper | Options | Languages | Common | Naming Style. -
Naming style settings for C# by choosing ReSharper | Options | Languages | C# | C# Naming Style. -
Naming style settings for VB.NET by choosing ReSharper | Options | Languages | Visual Basic .NET | VB Naming Style. -
Naming style settings for ASP.NET by choosing ReSharper | Options | Languages | ASP.NET | Web Naming Style. -
Naming style settings for XAML by choosing ReSharper | Options | Languages | XAML | Xaml Naming Style.
Note
Most procedures below assume that the user configures common naming style. Steps for configuring language-specific naming
styles are exactly the same.
-
To configure a naming style for predefined entities -
To create a user-defined naming rule -
To create a list of abbreviations -
To override common naming style with a language-specific naming style
To configure a naming style for predefined entities
- Choose ReSharper | Options | Languages | Common | Naming Style.
You can start configuring naming rules right from the text editor where ReSharper detects an incorrectly named symbol. When ReSharper displays a warning or suggestion to rename a symbol, press Alt+Enter and choose Change settings for rule... from the list of quick-fixes. When the Edit Rule Settings dialog box for the corresponding entity opens, proceed with step 4.
Tip
- In the Naming Style tab, select one of predefined entities.
- Click Edit
. The Edit Rule Settings dialog box displays:
- Configure name prefix, name suffix and naming style for the rule selected in the list at the top of the dialog box.
- Optionally, create additional rules for the selected code entity by clicking Add
and configuring prefix, suffix and naming style for the new rule.
When there are several rules for a single entity, one of them acts as the default rule (highlighted with bold). ReSharper doesn't display naming suggestions if a symbol matches at least one of configured rules. However, if a symbol doesn't match any rules, ReSharper suggests renaming it in accordance with the default rule.
Note
- Optionally, reorder the sequence of rules by clicking Move Up
or Move Down
.
- Optionally, remove unnecessary rule by clicking Remove
.
- Clear the Enable inspections check box to prevent ReSharper from inspecting the selected code entity for naming style compliance. This setting applies to all naming rules for the current entity.
- Click OK to close the Edit Rule Settings dialog box.
- Click OK to close the ReSharper Options dialog box.
To create a user-defined naming rule
- Choose ReSharper | Options | Languages | Common | Naming Style.
- In the Naming Style tab, click Advanced settings. The Advanced Naming Settings dialog box displays:
- Click Add
to create a custom naming rule. The Edit Extended Naming Rule dialog box displays:
- In the Rule Description text box, specify a name for the new extended rule.
- In the Affected entitites area, select code entitites that the extended rule should cover.
- Use Access rights and Static/non-static areas to further constrain the scope of the extended rule.
- In the Naming style tab, configure one or more rules according to steps 4-6 of the procedure above:
To configure a naming style for predefined entities . - Click OK to close the Edit Extended Naming Rule dialog box.
- Click OK to close the ReSharper Options dialog box.
To create a list of abbreviations
- Choose ReSharper | Options | Languages | Common | Naming Style.
- In the Naming Style tab, click Advanced settings. The Advanced Naming Settings dialog box displays:
- Add abbreviations that ReSharper should not warn you about in Edit abbreviations as plain text (UPPER CASE only) area. Use returns, commas, semicolons or spaces as delimiters.
- Click OK to close the Advanced Naming Settings dialog box.
- Click OK to close the ReSharper Options dialog box.
Tip
You can also add abbreviations to the list from the text editor. When ReSharper detects a symbol name that contains an abbreviation
which is not in the list, click Alt+Enter and select Add... to the abbreviations list:
To override common naming style with a language-specific naming style
- Choose one of the following:
- ReSharper | Options | Languages | C# | C# Naming Style
- ReSharper | Options | Languages | Visual Basic .NET | VB Naming Style
- Click Override common settings at the top of the selected tab.
- Configure a language-specific naming style as shown in procedures
To configure a naming style for predefined entities andTo create a user-defined naming rule above.
