Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically rename class to match file name

I have a class A in file B.cs. Now I want to rename this class to match the file name (B).

Is there a refactoring or context action in VS or ReSharper which automatically can do this renaming for me without typing in the new name matching file name?

Example

Before renaming:

File B.cs:

class A {}

After automatically renaming:

File B.cs:

class B{}

Update

The opposite (automatically rename file to match class name) is not an option because all these file renamings are implemented as DELETE+ADD. But then I would lose change history of that file in Perforce because all VS-Plug-ins for VS-Perforce-connection do not support move/add+move/delete actions for renaming.

like image 277
thersch Avatar asked Jul 16 '12 15:07

thersch


1 Answers

In Visual Studio, you can right click on the class name inside the .cs file and rename it by choosing "Refactor --> Rename". It will give you the option to refactor it.

like image 170
Alex Mendez Avatar answered Oct 09 '22 06:10

Alex Mendez