5

A在文件中有一个类B.cs。现在我想重命名这个类以匹配文件名(B)。

VS 或 ReSharper 中是否有重构或上下文操作可以自动为我执行此重命名,而无需输入与文件名匹配的新名称?

例子

改名前:

文件 B.cs:

class A {}

自动重命名后:

文件 B.cs:

class B{}

更新

相反(自动重命名文件以匹配类名)不是一个选项,因为所有这些文件重命名都是作为 DELETE+ADD 实现的。但是我会在 Perforce 中丢失该文件的更改历史记录,因为 VS-Perforce-connection 的所有 VS-Plug-ins 都不支持重命名的移动/添加+移动/删除操作。

4

4 回答 4

3

在 Visual Studio 中,您可以右键单击 .cs 文件中的类名并通过选择“重构 --> 重命名”来重命名它。它将为您提供重构它的选项。

于 2012-07-16T15:08:33.750 回答
2

We recently did a large refactor of several files, changing them from "Controllers" to "Services". After plodding through a few of them with ReSharper, I decided I should rename "BaseController" to "BaseService". Ding! ReSharper offered to rename all subclasses and replace "Controller" with "Service".

于 2015-09-02T14:07:28.740 回答
1

使用 Resharper,您可以使用 Ctrl+R,O

enter image description here

PS我使用Resharper 6.1

于 2012-07-16T15:12:23.120 回答
1

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?

With ReShaper 8.1 it is possible. Just put a cursor on the class name, hit alt + Enter to bring up the options then Select 'Rename file to match type name' and you are good.

enter image description here

于 2016-12-02T12:13:50.907 回答