是否可以从 NDepend 分析中排除整个命名空间?

发布于 2024-12-04 07:33:33 字数 133 浏览 1 评论 0原文

我有一个设置,其中 Visual Studio 2010 运行测试覆盖率分析,并且它的输出在集成构建期间被 NDepend 吸收。

一些程序集包含需要被 NDepend 忽略的生成代码。
有办法做到这一点吗?最好是整个命名空间。

I have a setup where Visual Studio 2010 runs test coverage analysis and it's output is absorbed by NDepend during an integration build.

A few assemblies contain generated code that needs to be ignored by NDepend.
Is there a way to do this? Preferably an entire namespace.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温柔少女心 2024-12-11 07:33:33

LINQ 上的代码查询和规则 (CQLinq) 确实提供了一种工具来忽略生成的代码。

有一个名为 JustMyCode 的方便的预定义域,其类型为 ICodeBaseView

JustMyCode 表示 CQLinq 的一种工具,用于从 CQLinq 查询结果中消除生成的代码元素。例如,以下查询将仅匹配不是由工具(例如 UI 设计器)生成的大型方法:

from m in JustMyCode.Methods where m.NbLinesOfCode > 30 select m

生成的代码元素集由前缀为 CQLinq 关键字 notmycode 的 CQLinq 查询定义。例如,下面的查询匹配名称以 ".designer.cs" 结尾的源文件中定义的方法:

notmycode from m in Methods where
  m.SourceFileDeclAvailable && 
  m.SourceDecls.First().SourceFile.FileName.ToLower().EndsWith(".designer.cs")
select m

CQLinq 查询运行程序在依赖于 < 的查询之前执行所有 notmycode 查询。 strong>JustMyCode,因此域 JustMyCode 被一次性定义。显然,如果 notmycode 查询依赖于 JustMyCode 域,CQLinq 编译器会发出错误。

有 4 个默认的 notmycode 查询,可以轻松调整以满足您的需求。请注意,命名空间没有默认的 notmycode 查询,但您可以创建自己的查询:

Code Query and Rule over LINQ (CQLinq) indeed provides a facility to ignore generated code.

There is the convenient predefined domain named JustMyCode of type ICodeBaseView.

The domain JustMyCode represents a facility of CQLinq to eliminate generated code elements from CQLinq query results. For example the following query will only match large methods that are not generated by a tool (like a UI designer):

from m in JustMyCode.Methods where m.NbLinesOfCode > 30 select m

The set of generated code elements is defined by CQLinq queries prefixed with the CQLinq keyword notmycode. For example the query below matches methods defined in source files whose name ends up with ".designer.cs":

notmycode from m in Methods where
  m.SourceFileDeclAvailable && 
  m.SourceDecls.First().SourceFile.FileName.ToLower().EndsWith(".designer.cs")
select m

The CQLinq queries runner executes all notmycode queries before queries relying on JustMyCode, hence the domain JustMyCode is defined once for all. Obviously the CQLinq compiler emits an error if a notmycode query relies on the JustMyCode domain.

There are 4 default notmycode queries, easily adaptable to match your need. Notes that there is no default notmycode queries for namespaces but you can create your own one(s):

走过海棠暮 2024-12-11 07:33:33

在“重构方法的快速摘要”中找到了这一点,

// Here are some ways to avoid taking account of generated methods.
!( NameIs "InitializeComponent()" OR
   // NDepend.CQL.GeneratedAttribute is defined in 
   // the redistributable assembly $NDependInstallDir$\Lib\NDepend.CQL.dll
   // You can define your own attribute to mark "Generated".
   HasAttribute "OPTIONAL:NDepend.CQL.GeneratedAttribute") 

但这并不能解决修改每个 CQL 查询以确保它们都忽略生成的代码的需要。

Found this in the "Quick summary of methods to refactor"

// Here are some ways to avoid taking account of generated methods.
!( NameIs "InitializeComponent()" OR
   // NDepend.CQL.GeneratedAttribute is defined in 
   // the redistributable assembly $NDependInstallDir$\Lib\NDepend.CQL.dll
   // You can define your own attribute to mark "Generated".
   HasAttribute "OPTIONAL:NDepend.CQL.GeneratedAttribute") 

But that doesn't address the need to modify every CQL query to ensure they all ignore the generated code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文