如何使用 ReSharper 在可以转换为私有的解决方案中列出 public 方法?

How can I use ReSharper to list public methods in a solution which can be converted to private?

在我的 C# winforms 项目中,定义了大量仅在内部使用的方法。

例如

public void AddPrimaryKeyProperty(string primaryKey)
{
    AddProperty(PrimarykeyProperty, primaryKey);
}

public void AddProperty(string propertyName, object propertyValue)
{
    //...
}

我熟悉 "Find usages" 功能,但希望能够生成可转换为私有方法的列表。在上面的例子中,AddProperty() 可以转换为 private.

是否存在这样的功能?

Resharper 会为您执行此操作,但您必须打开解决方案范围的分析,并让所有 projects/assemblies 在您的解决方案中使用您的 class(即:如果有一个程序集使用您的方法但不是当前 Visual Studio 解决方案的一部分,那么 ReSharper 不会知道它并会说您可以将方法设为私有)。

有关解决方案范围分析的详细信息,请参阅https://www.jetbrains.com/help/resharper/2017.1/Code_Analysis__Solution-Wide_Analysis__Solution-Wide_Code_Inspections.html

具体来说,它提供了一个代码检查列表,在启用解决方案范围分析时可用,包括Members and types that can be made internal, private or protected instead of public

然后您可以使用各种检查报告(或 "Inspection Options" 上下文 window -- 见下文)来查找此特定代码检查的所有实例。