English 中文(简体)
Is it possible with nDepend and CQL today to ask for classes directly using classes of a derived type?
原标题:

Been reading through a lot of Q s and posts and see that subqueries/nested queries/query composition will not be supported until the next version. However I m not sure if that is what I need, in my head it I would write it that way but I might be complicating things.

I imagine it like

WARN IF Count > 0 IN
SELECT TYPES WHERE
      IsDirectlyUsing "MTNE.Web.OneWeb.^.*p{Proxy}+$" IN
      SELECT TYPES WHERE DeriveFrom "System.Web.Services.Protocols.SoapHttpClientProtocol"

So what I d like to do is check if types are directly using other types in a given namespace which has the suffix Proxy, and that the proxy type is derived from SoapHttpClientProtocol. If a type is directly using the proxy type announce a warning.

Suggestions, hints, tips, pointers or answers anyone?

问题回答

There are several ways to write the query asked with Code Rule over LINQ Query (CQLinq). Certainly the most elegant, concise and optimized way is:

warnif count > 0
let soapClientTypes = Application.Types.Where(t => t.DeriveFrom("System.Web.Services.Protocols.SoapHttpClientProtocol"))
let mnteTypes = Application.Types.WithFullNameLike(@"MTNE.Web.OneWeb.^.*p{Proxy}+$").ToHashSet()
from t in soapClientTypes.UsingAny(mnteTypes)
select new { t, 
             mnteTypesUsed = t.TypesUsed.Intersect(mnteTypes) }

Notice how we first define 2 sets, and also use the extension method ToHashSet() to optimize the execution of the Intersect() method.

Notice also the usage of the method UsingAny() that, in a single call, perform a lot of work.





相关问题
Building CQL in NDepend for verifying MVVM patterns

I wanted to verify few design patterns in C# code by static analysis. I want to verify these using NDepend. The application is built with MVVM design style, so typical design patterns that I would ...

CQL request composition

Is it possible to compose requests in CQL ? I would like to write something like: SELECT TYPES FROM ASSEMBLIES "myassemblie" WHERE IsUsing SELECT METHODS FROM ASSEMBLIES "myotherassemblie" WHERE ...

Ndepend CQL to query types out of assembly wildcard

In order to determine what low-level framework types a web application is directly using, one has to define each and every assembly involved. SELECT TYPES FROM ASSEMBLIES "Company.System.Framework", "...

How to restrict NDepend methods query on type attribute

I m trying to get NDepend to identify long methods using a modified version of the standard "Methods too big" query. I don t want to report long methods that the developers have little control over, ...

热门标签