简体   繁体   English

如何轻松找到未使用的公共方法/属性

[英]How to easyily find unused public methods/properties

I have a .Net(C#) solution. 我有一个.Net(C#)解决方案。 The solution contains bunch of projects. 该解决方案包含大量项目。 The projects were implemented not by me. 这些项目不是我实施的。 It is not a framework, it means that I need to have amount of public methods/properties as less as possible. 它不是一个框架,它意味着我需要尽可能少的公共方法/属性。 My task is to identify methods and properties which are not used, but exist in the projects. 我的任务是确定未使用但存在于项目中的方法和属性。 Well, I can find private methods which are not used using R#. 好吧,我可以找到不使用R#的私有方法。 But it is completely unclear how to find public methods/properties which are not used. 但是如何找到未使用的公共方法/属性是完全不清楚的。

I heard that they have NDepend tool, but it is not very simple tool, is it. 我听说他们有NDepend工具,但它不是很简单的工具,是吗。

So, the question is: could you please point to a tool which can be used to identify methods which are not used in a solution. 所以,问题是:请你指出一个工具,可以用来识别解决方案中没有使用的方法。 It is OK with me to have command line tool or something pretty simple. 我可以使用命令行工具或非常简单的东西。

UPD: I tried to use trial NDepend. UPD:我试过使用试用NDepend。

Well, first of all it seems like it is possible to see public methods (properties are represented as get_ set_ methods) which are not used in this particular assembly. 好吧,首先,似乎可以看到公共方法(属性表示为get_set_方法),这些方法未在此特定程序集中使用。

But NDepend does not recognize if the public method is used from another project/assembly, which is a part of the solution and shows the method as unused. 但NDepend无法识别公共方法是否来自另一个项目/程序集,这是解决方案的一部分,并将该方法显示为未使用。 But this is not true. 但是这是错误的。

UPD2: mcintyre321 advised to use R#. UPD2:mcintyre321建议使用R#。 Please read a first comment below. 请阅读下面的第一条评论。

If you turn on solution wide analysis in ReSharper (5.0 and above) it will flag them for you. 如果您在ReSharper(5.0及更高版本)中启用解决方案范围的分析,它将为您标记它们。 This includes public methods. 这包括公共方法。

Heck I have done it old school. 哎呀,我做过旧学校。 I just comment out methods I don't think are being used and build. 我只是评论了我认为没有使用和构建的方法。 If I get an error, then I leave it there. 如果我收到错误,那么我就把它留在那里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM