1

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

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

4

1 回答 1

1

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
于 2013-01-16T21:04:25.590 回答