检查 NotImplementedExceptions 的 FxCop 规则
我希望每晚构建一次检查我的 .NET 代码中有多少个 NotImplementedExeption,因此希望我们可以在发布之前将它们全部删除。 我的第一个想法是 FxCop 可能是一个很好的工具来做到这一点。 有人有这方面的自定义 FxCop 规则吗? 我该如何自己创建一个呢?
I'd like to have the nightly build check for how many NotImplementedExeptions there are in my .NET code so hopefully we can remove them all before releasing. My first thought is that FxCop might be a good tool to do this. Does anyone have a custom FxCop rule for this? How would I go about creating one myself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果超过 10 个方法创建 NotImplementedException,这样的单元测试将会失败。 失败时,它将报告创建此异常的所有方法。
代码库的创建方式如下:
Snippet 使用 Lokad 共享库。
Unit test like this will fail if more than 10 methods create NotImplementedException. On failing it will report all methods that create this exception.
Where codebase is created like this:
Snippet uses Lokad.Quality.dll from the Lokad Shared Libraries.
我实际上已经实现了一个,并在这个答案中显示了代码。
I've actually implemented one and shown the code in this answer.
网上有大量关于如何制定自己的 FxCop 规则的资源,但由于“NotImplementedException”是一个如此独特的名称,您可能只需计算它在文件文本中出现的次数即可。 为所有 .cs 文件创建一个 ItemGroup,然后使用适当的 DOS 命令(例如“find /c”)并通过 EXEC 任务获取计数作为输出。
There's tons of resources on the net about how to make your own FxCop rule, but since 'NotImplementedException' is such a unique name, you could probably just do a count of its occurence in the text of the files. Create an ItemGroup for all the .cs files and then use an appropriate DOS command (such as "find /c") and get the count as the output, via the EXEC task.
有时应该抛出
NotImplementedExeption
——一个例子是如果您有IBindingList
的部分实现。有大量的资源 在那里 创建 自定义 fxCop 规则。 但是,“在解决方案中查找”可能是一种合适的方法(假设您在自动构建中不需要它)
There are times when a
NotImplementedExeption
should be thrown -- one example would be if you've a partial implementation ofIBindingList
.There are plenty of resources out there for creating custom fxCop rules. However, a "find in solution" might be a suitable approach (on the assumption that you're not needing this in an automated build)