如何使用 ReSharper 一次性更改多个方法的访问修饰符?

发布于 2024-09-30 10:33:22 字数 261 浏览 5 评论 0原文

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 技术交流群。

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

发布评论

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

评论(2

-柠檬树下少年和吉他 2024-10-07 10:33:22

不可以。目前,除了 Code Cleanup 之外,无法将 ReSharper 修复批量应用到所选内容,但 Code Cleanup 不支持更改可见性。
您能做的最好的事情就是利用名为查找代码问题:

  1. 选择ReSharper>检查>解决方案中的代码问题或项目中的代码问题。
    或者,在解决方案资源管理器中选择一个文件或文件夹,单击鼠标右键,然后选择“查找代码问题”。您将在检查结果工具窗口中看到问题列表。
  2. 单击检查结果工具窗口中的“过滤问题”。
  3. 仅保留与成员可见性相关的问题类型,例如“成员可以设为私有”、“成员或类型可以设为内部”等。
  4. 返回检查结果中的问题列表,并修复突出显示的可见性一 -通过单击 Enter 在问题所在的代码位置打开编辑器,按 Alt+Enter 进行修复,按 Ctrl+Alt+V(Visual Studio 键盘方案)返回到“检查结果”窗口。

此解决方法仅适用于 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:

  1. Select ReSharper > Inspect > Code Issues in Solution or Code Issues in Project.
    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.
  2. Click "Filter issues" in the Inspection Results tool window.
  3. Leave only the issue types that are related to member visibility, for example "Member can be made private", "Member or type can be made internal" etc.
  4. Get back to the list of issues in Inspection Results, and fix highlighted visibility one-by-one by clicking Enter to open the editor in the code position where the issue is, Alt+Enter to fix, and Ctrl+Alt+V (Visual Studio keyboard scheme) to get back to the Inspection Results 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.

亣腦蒛氧 2024-10-07 10:33:22

使用 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?

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