【问题标题】:Finding "Dead" assemblies with NDepend使用 NDepend 查找“死”程序集
【发布时间】:2012-06-10 14:17:19
【问题描述】:

我正在为我的一个客户评估 NDepend 工具,想知道是否有人可以就以下查询提供帮助:

// <Name>Potentially dead Assemblies</Name>
warnif count > 0 
    from a in JustMyCode.Assemblies where
       a.NbTypesUsingMe == 0
       select a

虽然这提供了一个很大的列表,但我还想检查唯一的引用是否来自测试项目,例如 MyNamespace 仅由 MyNamespace.Tests 引用。

如何做到这一点?我还没有找到有关创建不采用常量的 IsUsedBy 的文档。

此致,

马丁

【问题讨论】:

    标签: ndepend cqlinq


    【解决方案1】:

    对于匹配死程序集,你不需要计算类型,只需要使用我来计算程序集:

    warnif count > 0 
    from a in JustMyCode.Assemblies where
      a.AssembliesUsingMe.Count() == 0
      select a
    

    如果您想使用程序集匹配类型的条件,您可以编写如下内容:

    warnif count > 0 
    from a in JustMyCode.Assemblies
    let typesUser =  Application.Types.Using(a)
    where typesUser.Count() == 0 ||
          typesUser.ParentNamespaces()
          .WithNameWildcardMatchNotIn("MyNamespace.Tests*").Count() == 0
    select a
    

    请注意,在前面的查询中,我们甚至没有对 typesUser 进行迭代(使用 typesUser.Where(t =&gt; ...)),而是使用 NDepend.API 设置方法,例如 WithNameWildcardMatchNotIn()

    【讨论】:

    • 将通配符更改为“Test”以捕获所有测试项目(无标准命名约定),这可以按要求工作。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 2011-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多