【问题标题】:NDepend: Get average LOC per methodNDepend:获取每个方法的平均 LOC
【发布时间】:2012-12-30 23:07:59
【问题描述】:

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

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

【问题讨论】:

    标签: cql ndepend cqlinq


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 2021-01-30
      • 1970-01-01
      • 1970-01-01
      • 2013-02-06
      • 1970-01-01
      • 1970-01-01
      • 2013-08-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多