如何使用 ReSharper 重新格式化命名样式?
我有几页代码需要加强命名风格,例如使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不相信 ReSharper 有办法像你想要的那样进行批量重命名。更改 C# 命名样式肯定会突出显示(作为警告)那些需要更改的局部变量,但代码清理不会为您更正它们。
有时,重命名变量以匹配约定可能会导致一个符号与已存在的另一个符号发生冲突;我想这就是 ReSharper 不允许批量重命名的原因。
两个 ReSharper 快捷键可能会使此过程变得非常快(假设您已采用 ReSharper 的 Visual Studio 快捷键 ):
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):
从 R# 8 开始,可以选择修复范围内的问题。
更多信息
Starting from R# 8, there's the option to fix an issue in scope.
More info
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.)
它包含在 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.