Resharper 或 CodeRush - 将标志从负更改为正
我有一个带有否定标志的类(“DoNot{Action}”)。我想将此标志更改为肯定的“Do”并更改代码中的所有检查,基本上否定它们。有这样的重构吗?
这是一个例子。如果我将标志 DoNotFilter 更改为 DoFilter,则查看此标志的所有代码都应相应更改。
public bool DoNotFilter
{get;private set;}
更改为
public bool DoFilter
{get;private set;}
所以
if (attribute.DoNotFilter == true)
需要更改为
if (attribute.DoFilter == false)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您也许能够在 ReSharper 中进行内联属性重构来执行您想要的操作。不过,我不确定它是否适用于属性。
示例:
现在更改为:
现在重构 DoNotFilter 和内联属性:
如果您尝试这样做,请务必首先将所有内容签入源代码管理! :) 没有保证!
您还可以删除多余的比较,将 if 简化为:
You might be able to get the Inline Property refactoring in ReSharper to do what you want. I'm not sure if it will work with attributes, though.
Example:
Now change to:
Now refactor DoNotFilter and Inline Property:
If you try this, be sure to check everything in to source control first! :) No warranties!
You can also Remove redundant comparision to get the if down to:
您可以使用 Visual Studio 查找和替换对话框。要启动该对话框,请按 Ctrl+H。
确保选中“使用”复选框,并在下拉列表中选择“正则表达式”。我还会选中“搜索隐藏文本”和“搜索”复选框。
在“查找内容”中输入:
在“替换为”中输入:
Do\1
它将删除所有出现的 DoNotXXX 中的“Not”。
接下来让替换
为
如果您关闭了“查找和替换”对话框,请再次按 Ctrl+H。
在“查找内容”中输入:
在“替换为”中输入:
Do\1 == false
You can use Visual Studio Find and Replace dialog. To lunch the dialog press Ctrl+H.
Make sure that "Use" check box is checked and in dropdown list "Regular expression" is selected. I also would check "Search hidden text" and "Search up" check boxes.
In "Find what" type:
<DoNot{:i+}
In "Replace with" type:
Do\1
It will remove "Not" In all occurrences of DoNotXXX.
Next let replace
with
If you closed Find and Replace dialog, press Ctrl+H again.
In "Find what" type:
<Do{:i+} == true
In "Replace with" type:
Do\1 == false