NDepend如何计算代表的参数编号?

时间:2012-06-06 12:45:29

标签: ndepend

我们使用NDEPEND CQL请求在代码上设置了一些质量约束:

  

WARN IF Count> 0选择前10个方法,其中NbParameters> 6

定义具有5个参数的委托时,例如:

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

然后质量约束打破了源代码中不存在的函数(但可能在编译代码中)并且有2个附加参数:

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

如何解决这个障碍?

1 个答案:

答案 0 :(得分:2)

CQL无法轻松解决此问题,但自NDepend v4以来Code Rule over LINQ (CQLinq)已发布。

CQLinq具有定义 JustMyCode 的功能,因此消除了生成的方法,如 BeginInvoke(IArg,IArg,IArg,IArg,IArg,AsyncCallback,Object)。这在[{3}}

中有解释

基本上,默认和可自定义的代码规则Defining the code base view JustMyCode with notmycode prefix会丢弃委托类型及其方法,因为它们始终是生成的。

// <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 }
相关问题