违反Demeter法则的搜索工具? [英] Law of Demeter violation search tool?

查看:96
本文介绍了违反Demeter法则的搜索工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道我可以在C#应用程序中使用的工具来查找可能违反Demeter的法律吗?我知道这会带来很多误报,但我认为它仍然有用.尤其是在早期设计过程中.

解决方案

如果您只是在寻找 something.somethingelse.violation ,则可以使用Visual Studio.

在查找"对话框中,选中底部的使用"框,然后选择正则表达式".

不是很健壮,但是您可以使用< [:a _] + \.([:a _] + \.)+ [:a _] + 查找上面的图案.

更好的工具是解决方案目录上的 grep 或类似名称,因此您可以使用更强大的正则表达式选项(例如,负向后看),从而可以排除使用>指令和 namespace 声明.

适用于Windows的grep

您可能会非常迅速地编写一个.NET应用程序,该应用程序将使用给定的.NET Regex递归给定目录并搜索.cs和/或.vb文件,该应用程序具有环顾四周,但是使用VS的优势当然是您将保留在源代码编辑器中.

Does anybody know of a tool that I could use with a C# application to find possible Law of Demeter violations? I know that it would give a lot of false positives, but I think it could still be useful. Especially during the early design process.

解决方案

If you're just looking for something.somethingelse.violation, then you can use Visual Studio.

In the find dialog, check the box at the bottom to "Use" and select "Regular Expressions."

Not very robust, but you can use <[:a_]+\.([:a_]+\.)+[:a_]+ to find the pattern above.

A better tool would be grep or similar on the solution directory, so you can use more powerful regex options like negative lookbehind, which would allow you to exclude things like using directives and namespace declarations.

grep for Windows

You could probably very quickly write a .NET app that would recurse a given directory and search .cs and/or .vb files for same, using .NET Regex, which has lookarounds, but of course the advantage of using VS is that you remain right in the source code editor.

这篇关于违反Demeter法则的搜索工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆