检测 C# 中的死代码
如何检测 C# 应用程序中的死代码?
How can I detect dead code in my C# application?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何检测 C# 应用程序中的死代码?
How can I detect dead code in my C# application?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
ReSharper 可以处理这个问题。您还可以查看 NDepend。
如果您不想为其中任何一个付费,我相信您可以使用 FxCop 分析您的项目,它也会识别死代码。
ReSharper can handle that. You could also check out NDepend.
If you don't feel like paying for either of those, I believe you can analyze your project with FxCop and it will also identify dead code.
编译您的代码并检查错误列表中的警告。以下代码:
产生此警告:
JetBrains ReSharper (http://jetbrains.com/resharper)* 等工具也可以动态执行此分析并突出显示死代码。
* ReSharper 是一个商业工具。
Compile your code and check the warnings in the Error List. The following code:
produces this warning:
Tools like JetBrains ReSharper (http://jetbrains.com/resharper)* can also perform this analysis on the fly and highlight dead code.
* ReSharper is a commercial tool.
Resharper 识别死代码和未使用的参数/局部变量,FxCop。
Resharper identifies dead code and unused parameters/locals and so does FxCop.
请注意,这些工具不会检测注释中的死代码。
例如,以下内容:
不会被检测为死代码。
截至 2020 年 7 月,我找不到任何可以检测注释中死代码的代码检查工具。因此我自己开发了一个(基于Roslyn)并在MIT许可下发布:
https://github.com/mristin/dead-csharp。
Mind that these tools do not detect the dead code in the comments.
For example, the following:
will not be detected as dead code.
As of July 2020, I could not find any code inspection tool that could detect dead code in the comments. Therefore I developed one on my own (based on Roslyn) and published it under MIT license:
https://github.com/mristin/dead-csharp.