MO2k4 / CleanCode

ReSharper/Rider Plugin
MIT License
64 stars 9 forks source link

Too many chained references for LINQ #110

Closed avinashtauro-arctechinfo closed 2 years ago

avinashtauro-arctechinfo commented 2 years ago

LINQ statements always show the ReSharper warning "Too many chained references. This might be violating the law of Demeter) Is there an easy way to avoid this warning, other than to "Disable with comment".

var cassettesQuery = _db.Denominations
            .Include(d => d.Currency)
            .Where(d => ContainsValidDispensingNotes(d, _dispenseDenominationValues))
            .Select(d => CreateCassette(d));

This is a revisit of the issues mentioned below https://github.com/hhariri/CleanCode/issues/15 https://github.com/hhariri/CleanCode/issues/20 https://github.com/MO2k4/CleanCode/issues/23

MO2k4 commented 2 years ago

Another way would be to increase the value in the configuration. I can take another look at this and see if it is possible to know if the methods are chained via linq, but as already mentioned in the other issue, that could lead to other nasty side effects.

avinashtauro-arctechinfo commented 2 years ago

I changed the config value from 3 to 4 and the warning on the above example went away. Am working on my other LINQ statements to try and get it down to 4. And it is actually is making my LINQ more readable and modular. Thanks for this extension.