Law of Demeter violation search tool? [closed]

感情迁移 提交于 2019-12-02 00:43:46

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/3460418/law-of-demeter-violation-search-tool

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!