Trying to find all methods that don't have a direct dependency on Microsoft.SharePoint.* or System.Web.UI.*

StackOverflow https://stackoverflow.com/questions/8400137

문제

I'm trying to write a CQL query in Visual NDepend to find all types and methods that don't directly depend on any type from a list of namespaces.

The Query I've built so far is this one:

SELECT METHODS
WHERE 
   !IsDirectlyUsing "NAMESPACE:Microsoft.*"
   AND !IsDirectlyUsing "NAMESPACE:System.Web.UI.*"
   AND !FullNameLike ".Test"
   AND !HasAttribute "System.CodeDom.Compiler.GeneratedCodeAttribute"
   AND FullNameLike "OurOwnNameSpaceHere"

But this still returns methods that accept a SPWeb as a parameter, so I must be missing something.

So I want to:

  • exclude any method that depends on any type inside any referenced Assembly which is inside a Microsoft.* namespace.

  • exclude any method that depends on any type inside any referenced Assembly which is inside a System.Web.Ui.* namespace.

  • exclude any generated method/type

  • exclude any method that is part of a project that has Test in the namespace.

Sample methods that fall through are:

public void SomeMethod(SPWeb web)
{
    ... // other code here
    SomeOtherMethod(web);
    ...
}
도움이 되었습니까?

해결책

You can try the following code query over LINQ (CQLinq query):

let dontUseTypes = Namespaces
                   .WithNameWildcardMatchIn("Microsoft.*", "System.Web.UI.*")
                   .ChildTypes()

from m in JustMyCode.Methods.Except(Methods.UsingAny(dontUseTypes))
where !m.ParentAssembly.Name.ToLower().Contains("test")
select m

The condition exclude any generated method/type is handled by the fact that we use JustMyCode.

Then, which methods or fields of SPWeb are used by the method still matched? NDepend can detect that a method uses a type only if it is using a member of the type.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top