如何使用 ReSharper 一次性更改多个方法的访问修饰符?
ReSharper 中是否有快捷方式可以将多个方法的访问修饰符从某项更改为另一项?
假设我将选择方法:
public void Method_1(){...}
private void Method_2(){...}
private void Method_3(){...}
public void Method_4(){...}
通过使用 ReSharper,我将把它们的访问修饰符更改为内部。
这可能吗?
Is there a short-cut in ReSharper to change more than one method's access-modifiers from something to something else?
Let's say I will choose methods:
public void Method_1(){...}
private void Method_2(){...}
private void Method_3(){...}
public void Method_4(){...}
And by using ReSharper I will change the acess-modifiers of them to internal.
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不可以。目前,除了 Code Cleanup 之外,无法将 ReSharper 修复批量应用到所选内容,但 Code Cleanup 不支持更改可见性。
您能做的最好的事情就是利用名为查找代码问题:
或者,在解决方案资源管理器中选择一个文件或文件夹,单击鼠标右键,然后选择“查找代码问题”。您将在检查结果工具窗口中看到问题列表。
此解决方法仅适用于 ReSharper 所说可以缩小可见性的方法。对于不以这种方式突出显示的方法,您只能在代码编辑器中一一使用其上下文操作(用铅笔图标标记的操作) - 当然,前提是您知道自己在做什么。
No. Currently there's no way to batch-apply ReSharper fixes to a selection apart from Code Cleanup, but Code Cleanup doesn't support changing visibility.
The best thing you can do is to make use of ReSharper feature called Find Code Issues:
Alternatively, select a file or folder in Solution Explorer, right-click, and select Find Code Issues. You'll get the list of issues in the Inspection Results tool window.
This workaround is only applicable to methods that ReSharper says can be narrowed in visibility. For methods that it doesn't highlight this way, you can only use its context actions (actions marked with pencil icons) one by one in the code editor - provided that you know what you're doing, of course.
使用 Resharper 无法做到这一点。为什么要把私有方法设置为内部方法呢?如果您将私有方法设为内部,则无需重构,对吧?
You can't do this with Resharper. Why make a private method internal anyway? If you are making a private method internal there is nothing to refactor, right?