2016-05-01 72 views
3

我已经将NDepend(14天试用版)安装为Visual Studio 2015 Extension,现在可以使用。如何使用NDepend查看代码度量lke Fan-In/Fan-Out

我想获得一些类的一些度量在我的解决方案:标识符

  • 长度
  • 风扇/扇出
  • 类的加权方法
  • 类的
  • 耦合对象

我没有在它的官方网站上找到任何有用的说明,有谁知道吗?

谢谢。

回答

5

您可以编写C# LINQ code queries以获取您所需的任何代码度量标准。入/扇出

from t in Application.Types 
select new { t, t.TypesUsed, t.TypesUsingMe } 

from t in Application.Types 
select new { t, t.CyclomaticComplexity } 

类对象的耦合(如this definition

类的加权方法

标识符

长度

from t in Application.Types 
select new { t, t.SimpleName.Length } 

风扇0

from n in Application.Namespaces 
let NumberOfClasses = n.ChildTypes.Count() 
let NumberOfLinks = n.ChildTypes.SelectMany(t => t.TypesUsed).Distinct().Count() 
select new { n, CBO = NumberOfLinks/(float)NumberOfClasses } 

然后,您可以将代码查询转换为代码规则,前缀为warnif count > 0,并保存该规则以在Visual Studio和/或您的BuildProcess中执行该规则。

// <Name>Type name shouldn't exceed 25 char</Name> 
warnif count > 0 
from t in Application.Types 
where t.SimpleName.Length > 25 
orderby t.SimpleName.Length descending 
select new { t, t.SimpleName.Length } 

enter image description here

+0

不过,我还在探索NDepend的,你可以看看这个问题:HTTP://stackoverflow.com/questions/37083906/how-to-use-cqlinq-to- get-metrics-of-methods-and-fields-within-a-single-query,这几乎是一回事,但我想我最好在单独的问题中讨论它,谢谢。 – VincentZHANG

+0

另外,方法的循环复杂度算法是什么?是否与此处所述相同:http://staff.unak.is/andy/StaticAnalysis0809/metrics/cyclomatic_complexity.html?我发现差异。 – VincentZHANG

+0

在此处查找有关NDepend CC的所有详情:http://www.ndepend.com/docs/code-metrics#CC –