Can I find number of methods without number of getters via CQL?
-
11-03-2021 - |
Domanda
I am using ndepend to find my code problems. And right now I found that there are too much false positives mistakes.
For example, I have a class that is not complex at all, but it does has many properties. So, I will get a warning from the NDepend that the class has too many mehods.
Here is the out-of-the-box NDepend rule to want classes with big number of methods:
WARN IF Count > 0 IN SELECT TYPES WHERE
NbMethods > 20
ORDER BY NbMethods DESC
Can I change the way that NDepend calculate number of methods, so I could exclude properties where I want?
Soluzione
Can I change the way that NDepend calculate number of methods, so I could exclude properties where I want?
Sergei, yes this is possible thanks to the following CQLinq rule:
warnif count > 0
from t in Application.Types
let methods = t.Methods
.Where(m => !m.IsPropertyGetter && !m.IsPropertySetter &&
!m.IsConstructor)
where methods.Count() > 20
orderby methods.Count() descending
select new { t, methods }
Here not only you'll get the number of methods, but for each type you'll get all methods: