2016-05-01 71 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 –