سؤال

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