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.
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):
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With