首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NDepend如何计算委托的参数号?

NDepend如何计算委托的参数号?
EN

Stack Overflow用户
提问于 2012-06-06 12:45:28
回答 1查看 126关注 0票数 2

我们使用NDEPEND请求对代码设置了一些质量对比:

在选择NbParameters >6的前10种方法中警告如果计数>0

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

代码语言:javascript
复制
delegate void MyDelegate(IArg arg1, IArg arg2, IArg arg3, IArg arg4, IArg arg5);

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

代码语言:javascript
复制
BeginInvoke(IArg, IArg, IArg, IArg, IArg, AsyncCallback,Object)

如何克服这一障碍?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-06 13:24:21

CQL很难解决这个问题,但是LINQ (CQLinq)上的代码规则在NDepend v4之后就发布了。

CQLinq提供了定义什么是JustMyCode的工具,从而消除了生成的方法,比如BeginInvoke(IArg,AsyncCallback,Object)。这在以下几个方面得到了解释:用非notmycode前缀定义代码基视图JustMyCode

基本上,默认和可自定义的代码规则丢弃从JustMyCode生成的类型放弃委托类型及其方法,因为它们总是生成的。

代码语言:javascript
复制
// <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 }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10914491

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档