如何使用 ReSharper 重新格式化命名样式?

发布于 2024-11-16 16:34:24 字数 227 浏览 3 评论 0原文

我有几页代码需要加强命名风格,例如使用 fooBar 而不是 FooBar 作为局部变量。由于显而易见的原因,我不想一一纠正。

我尝试摆弄可通过 ReSharper > 访问的代码清理配置文件。工具>清理代码>编辑个人资料。我无法找到一种方法来一次纠正所有命名样式,甚至无法使用键盘快捷键。经验丰富的 ReSharper 用户能否建议我如何解决这个问题?

I have several pages of code that need to have naming styles reinforced, e.g. use fooBar instead of FooBar for local variables. I don't want to correct it one by one for an obvious reason.

I tried to fiddle with the code cleanup profiles accessiable via ReSharper > Tools > Cleanup Code > Edit Profiles. I am not able to find a way to correct all naming style in one hit, or even with a keyboard shortcut. Could seasonsed ReSharper users advise how I can tackle this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一抹苦笑 2024-11-23 16:34:24

我不相信 ReSharper 有办法像你想要的那样进行批量重命名。更改 C# 命名样式肯定会突出显示(作为警告)那些需要更改的局部变量,但代码清理不会为您更正它们。

有时,重命名变量以匹配约定可能会导致一个符号与已存在的另一个符号发生冲突;我想这就是 ReSharper 不允许批量重命名的原因。

两个 ReSharper 快捷键可能会使此过程变得非常快(假设您已采用 ReSharper 的 Visual Studio 快捷键 ):

  1. Alt + PgDn - 转到下一个突出显示(错误、警告或建议)。这将使您能够快速地从一个错误命名的变量转到下一个。
  2. Alt + Enter - 打开“快速修复”菜单并选择“重命名...”。这将重命名变量并更新所有引用。

I don't believe ReSharper has a way to do a bulk rename like you want. Changing the C# Naming Styles will certainly highlight (as warnings) those local variables that need changing, but Code Cleanup won't correct them for you.

There are times when renaming a variable to match a convention might result in one symbol colliding with another symbol that already exists; I imagine that's why ReSharper doesn't allow the bulk rename.

Two ReSharper shortcuts may make this pretty quick (and this is assuming you have adopted ReSharper's shortcut keys for Visual Studio):

  1. Alt + PgDn - Go to next highlight (error, warning or suggestion). This will let you get from one misnamed variable to the next quite quickly.
  2. Alt + Enter - Open the "Quick Fix" menu and select "Rename...". This will rename the variable and update all references.
转瞬即逝 2024-11-23 16:34:24

从 R# 8 开始,可以选择修复范围内的问题。

  1. 转到任何出现此问题的位置
  2. 将光标放在其上
  3. 显示潜在的修复 (CTRL+)。
  4. 选择第一个选项“重命名为 xxx”,然后选择“修复解决方案中的命名”

更多信息

Starting from R# 8, there's the option to fix an issue in scope.

  1. Go to any occurrence of this issue
  2. Put the cursor on it
  3. Show potential fixes (CTRL+.)
  4. Select the first option 'Rename to xxx' and select 'fix naming in solution'

More info

缪败 2024-11-23 16:34:24

R# 有一个 SDK。也许您可以通过以下方式添加清理选项:

http://confluence .jetbrains.com/display/NETCOM/2.07+Code+Cleanup+%28R8%29

(我也在进行大规模命名重构,但才刚刚开始研究不知道这是否可行,或者需要付出什么努力。)

R# has an SDK. Perhaps you can add a cleanup option via this:

http://confluence.jetbrains.com/display/NETCOM/2.07+Code+Cleanup+%28R8%29

(I'm doing a mass naming refactor as well, but have only just started looking into writing something in their API. Don't know if this will work yet, or the effort involved.)

往昔成烟 2024-11-23 16:34:24

它包含在 resharper 2018 中,找到错误命名变量的出现,使用 resharper 上下文菜单修复解决方案中的所有出现。

Its included in resharper 2018, find an occurence of the incorrectly named variable, use the resharper context menu to fix all occurrence in the solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文