gpt4 book ai didi

c# - 如何使用 NDepend 查看代码指标 lke Fan-In/Fan-Out

转载 作者:行者123 更新时间:2023-11-30 14:50:18 24 4
gpt4 key购买 nike

我已经安装了 NDepend(14 天试用版)作为 Visual Studio 2015 扩展,现在可以使用了。

我想在我的解决方案中获得某些类的一些指标:

  • 标识符的长度
  • 扇入/扇出
  • 类的加权方法
  • 类对象的耦合

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

谢谢。

最佳答案

你可以写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 }

enter image description here

关于c# - 如何使用 NDepend 查看代码指标 lke Fan-In/Fan-Out,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36962197/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com