我们使用NDEPEND请求对代码设置了一些质量对比:
在选择NbParameters >6的前10种方法中警告如果计数>0
例如,当定义带有5个参数的委托时:
delegate void MyDelegate(IArg arg1, IArg arg2, IArg arg3, IArg arg4, IArg arg5);然后,质量约束破坏了一个函数,该函数在源代码中不存在(但可能在编译的代码中),并且有两个附加参数:
BeginInvoke(IArg, IArg, IArg, IArg, IArg, AsyncCallback,Object)如何克服这一障碍?
发布于 2012-06-06 13:24:21
CQL很难解决这个问题,但是LINQ (CQLinq)上的代码规则在NDepend v4之后就发布了。
CQLinq提供了定义什么是JustMyCode的工具,从而消除了生成的方法,比如BeginInvoke(IArg,AsyncCallback,Object)。这在以下几个方面得到了解释:用非notmycode前缀定义代码基视图JustMyCode
基本上,默认和可自定义的代码规则丢弃从JustMyCode生成的类型放弃委托类型及其方法,因为它们总是生成的。
// <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 }https://stackoverflow.com/questions/10914491
复制相似问题