ReSharper Web Help

The Rename family of refactorings helps change names of namespaces, classes, structs, methods, fields, local variables and other symbols (see also table below for details). All corresponding references in code are updated automatically.

The refactoring can be invoked from the text editor, from ReSharper tool windows (for example, Type Hierarchy) and sometimes from other views (Class View, Object Browser).

To rename a symbol
  1. Position the caret at the declaration or at a usage of a symbol in the text editor, or select it in another view or tool window.
  2. Choose ReSharper | Refactor | Rename, or press F2. The Rename wizard opens:
    Refactorings__Rename__dialog_box.png

     Note

    Controls available in the Rename wizard vary depending on a selected symbol. Local variables are renamed in dialogless mode using a drop-down list where you can select one of suggested names or specify a custom name.
  3. In the Name text box, specify a new name for the symbol.

     Tip

    ReSharper provides name completion in the Name text box, taking into account your naming style . To invoke name completion in any position on top of the existing name, or in the blank text box, press Ctrl+Space:
    Refactorings__Rename__name_completion.png
  4. If you want ReSharper to provide the list of related symbols in comments and string literals and possibly rename them, select Search in comments and string literals.
  5. Click Next. In simple cases, ReSharper immediately applies the refactoring. However, before it is completed, ReSharper could display the following additional wizard screens:
    • a. If there are related symbols that have names containing the string being changed (for example, read and write properties of a field or instances of a class, related file names, or even classes that implement an interface being renamed), the second page provides the list of these:
      Refactorings__Rename__related_symbols.png
      Select related symbols that you want ReSharper to rename along with the selected symbol, and click Next.
    • b. If you have previously selected Search in comments and string literals, ReSharper displays located usages (if any) in the following screen:
      Refactorings__Rename__comments_and_string_literals.png
      Select textual occurrences that you want ReSharper to rename, and click Next. If no conflicts are found, ReSharper will complete the refactoring.
ReSharper Rename refactorings

Symbol

Description

Namespace

Renames a namespace and automatically corrects all references to the namespace in code.

The following usages are renamed:

  • Namespace statements.
  • Using directives.
  • Qualified names of types.

 Tip

Along with renaming a namespace, you can change its nesting level. For example, you can rename A.B.C namespace toA.D.
Type

Renames an interface, class, struct, or enum and automatically corrects all references to the type in code.

The following usages are renamed:

  • Using directives.
  • Qualified names of types.

If the renamed type is located in file with the same name, ReSharper suggests to rename the file.

Method

Renames a method and automatically corrects all references to the method in code.

The following usages are renamed:

  • All method calls.
  • All methods that override or implement the selected method.
Field

Renames a field and automatically corrects all references to the field in code.

Property Renames a property and automatically corrects all references to the property in code.
Event Renames an event and automatically corrects all references to the event in code.
Parameter

Renames a method/constructor parameter and automatically corrects all references to the parameter in code.

The following usages are renamed:

  • Signature of the selected method and all methods that override or implement the method.
  • All parameter usages in the body of the selected method and all methods that override or implement the method.

If the selected method is a part of inheritance/implementation hierarchy, ReSharper will ask whether to rename the parameter in the whole hierarchy.

Local variable or constant

Renames a variable or constant and corrects all references in code.

ReSharper renames local variables (including constants) in dialogless mode. When you call the Rename refactoring for a local variable or constant, ReSharper suggests new variable names based on its type and context. You can either choose one of the suggested names or enter a custom name directly in the editor:

See Also

Procedures