2012-06-06 59 views
2

我們設置一些質量contraint上我們的代碼,使用NDepend的CQL請求:NDepend如何計算代表的參數數量?

WARN IF計數> 0 IN SELECT TOP 10方法WHERE NbParameters> 6

當定義用5個參數的代表,例如:

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

則質量約束打破上的函數,而不是(在編譯的代碼,但可能)存在於源代碼和具有2個addtional參數:

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

如何解決這個障礙?

回答

2

CQL不能輕易解決這個問題,但Code Rule over LINQ (CQLinq)自從NDepend v4發佈以後可以。

CQLinq自帶工具來定義什麼是JustMyCode,因此消除產生的方法,如的BeginInvoke(IArg,IArg,IArg,IArg,IArg,AsyncCallback的,對象)。解釋如下:Defining the code base view JustMyCode with notmycode prefix

基本上默認和可定製的代碼規則Discard generated Types from 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 }