0

I'm thinking about to build a tool that spots law of demeter violations in c# code. Obviously, I don't want to reinvent the wheel and build another tool if there is some alternative available, but I had no lucky on searching for such tool specifically for c# code.

There is another topic on stack overflow (here) on the same problem but I think that the solution suggested (e.g. using regex to discover LoD violations) will catch only simple violations. For example, consider the following code (and suppose that a person object already exists):

Wallet wallet = person.Wallet;
DriversLicense license = wallet.DriversLicense;

This is clearly a LoD violation (same as DriversLicense license = person.Wallet.DriversLicense), but it is harder to detect.

I found some threads about how to check law of demeter violations in c# here and here but no answers for specific tools.

Do you know any tool capable of spotting the kind of LoD violations previously presented in c# code?

Community
  • 1
  • 1
rpepato
  • 127
  • 4
  • Did you take a look [here](http://stackoverflow.com/questions/3460418/law-of-demeter-violation-search-tool)? Looks like a Regex might be able to do the job. – Pierre-Luc Pineault Jul 06 '13 at 03:19
  • Yeah... I saw this. I think that using Regex (or any other form of punctuation counting) will spot the most simple and naive case, but consider the following snippet of code: `Wallet wallet = person.Wallet; DriversLicense license = wallet.DriversLicense;` This is the same kind of violation, but harder to spot. I think that a tool capable to analyze many forms of LoD violations should be built over the Abstract Syntax Tree or over aspects, but I'm not so sure about the best approach yet. – rpepato Jul 06 '13 at 03:35

0 Answers0