Domanda

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?

È stato utile?

Soluzione

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:

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top