A custom rule has to be created in NDepend to check the availability of a particular method (e.g. Dispose) in some classes. A warning has to be given for classes that do not contain the method.
The following code gives all the classes that need to be checked for availability of the method:
let ManagerClasses =
from a in Application.Types
where a.IsClass && a.Name.EndsWith("Manager")
select a
The following code gives the classes that actually contain the method:
let ManagerClassesWithDispose =
from b in ManagerClasses
from m in b.Methods
where m.Name == "Dispose()"
select b
How to get the classes that do not contain the method? Is it possible to find (a-b) somehow in CQLinq?
In such situation you don't need to define a set through a let
clause, you can just write:
from a in Application.Types
where a.IsClass && a.Name.EndsWith("Manager") &&
a.Methods.WithSimpleName("Dispose").FirstOrDefault() == null
select a