NDepend:获取每种方法的平均LOC

时间:2013-01-16 15:17:33

标签: cql ndepend cqlinq

假设我在我的解决方案中设置了特定的方法。 如何在方法集中获得每个方法的平均代码行数?

这些数字通常显示在每个NDepend报告的统计部分(如Sum, Average, Minimum等),但我希望能够分别为这些数字编写查询。

1 个答案:

答案 0 :(得分:2)

CQLinq查询可能如下:

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

...或者更精确一点,这个查询可以重构为:

// 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