2

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?

Ruben
  • 6,367
  • 1
  • 24
  • 35
Abdul Rauf
  • 5,798
  • 5
  • 50
  • 70

1 Answers1

1

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
Patrick from NDepend team
  • 13,237
  • 6
  • 61
  • 92