开发者

How can NDepend be instructed to ignore EF classes?

开发者 https://www.devze.com 2023-03-30 05:42 出处:网络
I\'m having a little problem with NDepend not ignoring generated code. It\'s picking up issues around methods with too many parameters on the designer.cs file generated by EF when the entity data mode

I'm having a little problem with NDepend not ignoring generated code. It's picking up issues around methods with too many parameters on the designer.cs file generated by EF when the entity data model is created. The class is commented with an "auto-generated" annotation but is still being picked up by NDepend.

I can't seem to find how 开发者_高级运维to either force *.designer.cs to be ignored or even to ignore the specific file without wild cards. The closest I've come is this post from a couple of years ago where Patrick mentions plans to do this but nothing more.

Am I missing something? Is there an easy way to exclude this?


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. You can also create your additional notmycode queries:

  • Discard generated Assemblies from JustMyCode
  • Discard generated Types from JustMyCode
  • Discard generated and designer Methods from JustMyCode
  • Discard generated Fields from JustMyCode
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号