Frage

Does NDepend have a direct way to measure RFC (RFT) by CQL? Or do we have to write a CQL query for recursive counting invoked methods in used classes (types) our-self? If so, how does it look like? Similarly to this?

War es hilfreich?

Lösung

This is indeed possible thanks to the magic FillIterative() method. The only issue is that this code query can take a few seconds to run and you might need to adjust the query time-out (set to 2 seconds per default). Notice that this performance cost is due to the RFT definition, it doesn't come from a problem with the algorithm used.

Here is the code:

// <Name>RFT</Name>
from t in Application.Types
where !t.IsInterface && !t.IsEnumeration
let methodsUsedDirectly = 
   t.TypesUsed
    .Where(tUsed => !tUsed.IsThirdParty)
    .ChildMethods()
    .Where(m => m.IsUsedBy(t))

let methodsUsedIndirectly = methodsUsedDirectly
   .FillIterative(
         methods => methods.SelectMany(
                         m => m.MethodsCalled
                               .Where(mCalled => !mCalled.IsThirdParty))
   )
   .DefinitionDomain.ToArray()

let rftLoC = methodsUsedIndirectly.Sum(m=>m.NbLinesOfCode)

select new { t, 
   methodsUsedDirectly, 
   methodsUsedIndirectly,
   rft = methodsUsedIndirectly.Length,
   rftLoC }

By running this query, not only you get the RFT measure for each type, but you get also the RFT in terms of Lines of Code (i.e the sum of LoC of methods in the response) and you can also for each type, lists all methods in the response.

NDepend Code Query RFT Response for Type

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top