Resharper 重命名字段

发布于 2024-12-25 18:11:41 字数 250 浏览 2 评论 0 原文

我的任务是对未使用我们当前的代码风格约定编写的遗留代码库进行一些重大修改。这些更改足够广泛,以至于我在开始之前进行了一些清理和重构(有相当多的死代码)。困扰我的一件事是字段遵循 m_FieldName 命名约定,而我们现在使用 _fieldName。

Resharper 是否有某种方法可以自动重命名项目中的所有字段以遵循新约定?还有其他工具可以轻松做到这一点吗?即使通过简单的搜索/替换来删除前缀“m”也不是太困难,但我还没有找到一种自动方法来更改起始字母的大小写。

I've been tasked with making some significant modifications to a legacy codebase that was not written using our current code style conventions. The changes are extensive enough that I'm doing some cleanup and refactoring (there was quite a bit of dead code) before getting started. One of the things that's bugging me is that the fields are following the m_FieldName naming convention whereas we now use _fieldName.

Is there some way with Resharper to automatically rename all fields in the project to follow the new convention? Are there other tools that can readily do this? It's not too difficult to remove the prefixing 'm' with even a simple search/replace, but I haven't found an automated way to change the case of the starting letter.

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

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

发布评论

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

评论(2

再见回来 2025-01-01 18:11:41

最好使用 Visual Studio(正则表达式搜索/替换)将 查找/替换为 _

< 代表“单词开头”。

编辑:使用查找/替换似乎无法修改下划线后第一个字母的大小写。

因此,您必须连续执行此操作 26 次,如下所示:

Replace <m_A by _a
Replace <m_B by _b

然后就万事大吉了。也很有趣:-) 但应该只需要几分钟。

It might be better to just find/replace <m_ by _ using Visual Studio (regular expression search/replace).

The < stands for "beginning of word".

Edit: There seems to be no way, using Find/Replace, to modify the casing of that first letter after the underscore.

So you would have to do this operation 26 times in a row, like so:

Replace <m_A by _a
Replace <m_B by _b

and then you're all set. Fun, too :-) But it should only take a few minutes.

不如归去 2025-01-01 18:11:41

这似乎现在在 Resharper 中可用(我有 v10):

在此处输入图像描述

This seems to be available now in Resharper (I have v10):

enter image description here

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