ReSharper Help

Rename

ReSharper | Refactor | Rename…
F2
ReSharper_Rename

This refactoring allows you to change name of any symbol in your solution. All references to and usages of the symbol are updated automatically.

In this topic:

Using the refactoring for different C# entities

Here is the list of C# entities that you can rename with this refactoring:

  • Namespace
    You can also change its nesting level of the namespace. For example, you can rename namespace A.B.C to A.D.
  • Type
    If the renamed type is located in file with the same name, ReSharper renames the file, too.
    If the renamed type is a part of a hierarchy of types with similar names, e.g. class Foo : IFoo, you will be able to choose whether to rename the related types.
  • Method
    If the method is a part of inheritance/implementation hierarchy, the related methods are renamed as well.
    If the method has overloads, you will be able to choose whether to rename the overloads.
  • Field
    If the field is used in a property with a matching name, you will be able to choose whether to rename the property.
  • Property
    If the property has a backing field with a matching name, you will be able to rename the filed as well.
  • Parameter
    If the method is a part of inheritance/implementation hierarchy, or has overloads with a parameter of the same name and type, you will be able to rename parameters in the related methods, too.
  • Local variable
    ReSharper renames local variables without the dialog:
    Renaming local variable
  • Event
  • Delegate

Invoking the refactoring with a command

To rename a symbol and update all references and usages

  1. Select a symbol in one of the following ways:
    • In the editor, set the caret at the name of a symbol.
    • Select a symbol in the Solution Explorer.
    • Select a symbol in the File Structure window.
    • Select a symbol in the Class View.
    • Select a symbol in the Object Browser.
    • Select a symbol in the type dependency diagram.
  2. Do one of the following:
    • On the main menu, choose ReSharper | Refactor | Rename…
    • Right-click and choose Refactor | Rename on the context menu.
    • Press Ctrl+Shift+R and then choose Rename
    • Press F2.
    The Rename dialog will open.
  3. Type a new name for the symbol or use one of the suggested names.
    Refactorings__Rename__dialog_box
    ReSharper suggests new names for the symbol taking into account your naming style.
  4. ReSharper can provide the list of related symbols in comments and string literals and rename them on demand. If you need it, select the Search in comments and string literals.
  5. Click Next. If there are nothing related to the renamed symbol, ReSharper applies the refactoring. Otherwise, the wizard displays additional steps:
    • If there are related symbols with similar names, they are listed on the following step:
      Refactorings__Rename__related_symbols
      Select related symbols that you want to rename along with the selected symbol - you can accept the suggested names or specify new names in the New Name column.
    • If you have previously selected Search in comments and string literals and occurrences of the symbol name is found, they are listed on the following step:
      Refactorings__Rename__comments_and_string_literals
      Select textual occurrences that you want ReSharper to rename.
  6. If no conflicts are found, ReSharper performs the refactoring immediately. Otherwise, it prompts you to resolve conflicts.

Performing the refactoring in-place

You can rename a symbol by modifying its declaration right in the editor and then applying a quick-fix to invoke the solution-wide refactoring.

As soon as you change symbol's name at its declaration, a grey border appears around the name, notifying you that the refactoring is available. You can press Alt+Enter to find the refactoring in the action list:

ReSharper. Applying Rename refactoring inplace

Applicability in different languages

This feature is supported in the following languages/technologies:

C# VB.NET C++ HTML ASPX Razor JavaScript TypeScript CSS XML XAML RESX Build Scripts
feature_available feature_available feature_available feature_available feature_available feature_available feature_available feature_available feature_available feature_available feature_available feature_available feature_available

The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by Language section. Specifically:

See Also

Last modified: 30 June 2015