【发布时间】:2016-08-26 00:33:33
【问题描述】:
我已将 NDepend(14 天试用版)作为 Visual Studio 2015 扩展安装,现在可以使用。
我想在我的解决方案中获取一些类的一些指标:
- 标识符的长度
- 扇入/扇出
- 类的加权方法
- 类对象的耦合
我在其官方网站上没有找到任何有用的说明,有人知道吗?
谢谢。
【问题讨论】:
标签: c# .net code-metrics ndepend
我已将 NDepend(14 天试用版)作为 Visual Studio 2015 扩展安装,现在可以使用。
我想在我的解决方案中获取一些类的一些指标:
我在其官方网站上没有找到任何有用的说明,有人知道吗?
谢谢。
【问题讨论】:
标签: c# .net code-metrics ndepend
您可以写C# LINQ code queries 来获得几乎任何您需要的代码指标。
标识符的长度
from t in Application.Types
select new { t, t.SimpleName.Length }
扇入/扇出
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 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 }
【讨论】: