Domanda

We set some quality contraint on our code, using NDEPEND CQL request:

WARN IF Count > 0 IN SELECT TOP 10 METHODS WHERE NbParameters > 6

When defining a delegate with 5 arguments, for example:

delegate void MyDelegate(IArg arg1, IArg arg2, IArg arg3, IArg arg4, IArg arg5);

Then the quality constraint breaks on a function which is not present in source code (but probably in compiled code) and has 2 addtional arguments:

BeginInvoke(IArg, IArg, IArg, IArg, IArg, AsyncCallback,Object)

How to work around this impediment?

È stato utile?

Soluzione

CQL cannot easily solve this issue, but Code Rule over LINQ (CQLinq) released since NDepend v4 can.

CQLinq comes with facilities to define what is JustMyCode, hence eliminate generated methods like BeginInvoke(IArg, IArg, IArg, IArg, IArg, AsyncCallback,Object). This is explained in: Defining the code base view JustMyCode with notmycode prefix

Basically the default and customizable code rule Discard generated Types from JustMyCode discard delegate types, and their methods, because they are always generated.

// <Name>Discard generated Types from JustMyCode</Name>
// --- Make sure to make this query richer to discard generated types from NDepend rules results ---
notmycode
from t in Application.Types where

  // Resources, Settings, or typed DataSet generated types for example, are tagged with this attribute
  t.HasAttribute ("System.CodeDom.Compiler.GeneratedCodeAttribute".AllowNoMatch()) ||

  // Delegate types are always generated
  t.IsDelegate ||

  // Discard ASP.NET page types generated by aspnet_compiler.exe
  // See: http://www.ndepend.com/FAQ.aspx#ASPNET
  t.ParentNamespace.Name.EqualsAny("ASP", "__ASP") ||

  // Discard generated type ContractException
  t.Name == "__ContractsRuntime+ContractException" ||
  t.FullName == "System.Diagnostics.Contracts.RuntimeContractsAttribute" ||
  t.FullName == "System.Diagnostics.Contracts.__ContractsRuntime" ||

  // Discard all types declared in a folder path containing the word "generated"
  (t.SourceFileDeclAvailable &&
   t.SourceDecls.All(s => s.SourceFile.FilePath.ParentDirectoryPath.ToString().ToLower().Contains("generated")))

select new { t, t.NbILInstructions }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top