문제

Let's say I a have specific method set in my solution. How can i get an average number of code lines per method in the method set?

Those numbers are usually shown in the statistic section of each NDepend report (like Sum, Average, Minimum, etc) but I want to be able to write queries for such numbers separately.

도움이 되었습니까?

해결책

CQLinq query could be like following:

let totalLinesSum = JustMyCode.Methods.Where(t => t.IsPublic).Sum(t => t.NbLinesOfCode)
let methodsCount = JustMyCode.Methods.Where(t => t.IsPublic).Count()

let result = (double)totalLinesSum / methodsCount 

select (double?)result

...or a bit more refined, this query can be refactored like:

// Let define your methods set the way you need
// It is worth removing abstract method that have no LoC
let methodsSet = JustMyCode.Methods.Where(m => m.IsPublic && !m.IsAbstract)

let totalLoc = methodsSet.Sum(t => t.NbLinesOfCode)
let methodsCount = methodsSet.Count()
let avgLoc = (double)totalLoc / methodsCount 

select (double?)avgLoc
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top