Vin*_*ANG 3 .net c# ndepend code-metrics
我已经安装了NDepend(14天试用版)作为Visual Studio 2015扩展,它现在可以使用了.
我想在我的解决方案中获得一些类的一些指标:
我没有从官方网站上找到任何有用的指示,有人知道吗?
谢谢.
您可以编写C#LINQ代码查询以获得您需要的几乎任何代码度量.
标识符的长度
from t in Application.Types
select new { t, t.SimpleName.Length }
Run Code Online (Sandbox Code Playgroud)
扇入/扇出
from t in Application.Types
select new { t, t.TypesUsed, t.TypesUsingMe }
Run Code Online (Sandbox Code Playgroud)
加权方法
from t in Application.Types
select new { t, t.CyclomaticComplexity }
Run Code Online (Sandbox Code Playgroud)
类对象的耦合(根据此定义)
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 }
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用前缀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 }
Run Code Online (Sandbox Code Playgroud)