Trying to find all methods that don't have a direct dependency on Microsoft.SharePoint.* or System.Web.UI.*
-
28-10-2019 - |
문제
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.