插入以查找 null 初始值设定项
我最近发现对象的 null 初始值设定项是 http://www. codinghorror.com/blog/archives/000343.html 我有一个巨大的 C# 代码库,其中进行了很多此类初始化,我想知道是否有任何免费插件可以帮助我替换它。我尝试在网上搜索,但没有免费插件:(
I recently found out that having null initializer for objects are an overhead from http://www.codinghorror.com/blog/archives/000343.html
I have a huge C# codebase where in lots of such initializations are made,i want to know if there is any free plug in to help me replace it.I tried to search on net but no free plug ins:(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这不一定能帮助您自动修复它们,但如果您安装独立的 FxCop 1.36,您可以仅打开规则CA1805,它将找到您不必要初始化的所有位置。
(此规则不作为 Visual Studio 中内置代码分析规则的一部分提供。)
This won't necessarily help you automatically fix them, but if you install the standalone FxCop 1.36, you can turn on just rule CA1805, which will find all of the places you are initializng unnecessarily.
(This rule is not available as part of the built-in Code Analysis rules in Visual Studio.)
您是否发现这些空初始化会对您的应用程序造成性能影响?我不会费心去尝试修复那些不是真正问题的东西(并不是说它不是问题,只是我对此持怀疑态度)。
Have you identified that these null initializations are creating a performance hit to your application? I wouldn't bother trying to fix something that isn't really a problem (not saying it isn't, just that I am skeptical).
Jetbrains 的 Resharper 可以做到这一点,甚至更多。它还采用系统范围的分析,您可以使用它来查找此类故障。它还具有代码清理功能,如果配置为这样做,实际上可以自动删除所有不必要的初始化。
Jetbrains's Resharper can do this and much more. It also employs system wide analysis that you can use it to find faults like these. Also it has a code clean up feature which can actually remove all unnecessarily initializations automatically if configured to do so.