【发布时间】:2012-12-30 23:07:59
【问题描述】:
假设我在我的解决方案中设置了特定的方法。 如何获得方法集中每个方法的平均代码行数?
这些数字通常显示在每个 NDepend 报告的统计部分(如 Sum, Average, Minimum 等),但我希望能够单独编写对这些数字的查询。
【问题讨论】:
假设我在我的解决方案中设置了特定的方法。 如何获得方法集中每个方法的平均代码行数?
这些数字通常显示在每个 NDepend 报告的统计部分(如 Sum, Average, Minimum 等),但我希望能够单独编写对这些数字的查询。
【问题讨论】:
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
【讨论】: