3

I am in the process of evaluating the NDepend tool for a client of mine, and was wondering if anyone could provide assistance with the following query:

// <Name>Potentially dead Assemblies</Name>
warnif count > 0 
    from a in JustMyCode.Assemblies where
       a.NbTypesUsingMe == 0
       select a

Although this provides a large list, I would also like to check if the only reference is from a test project such as MyNamespace only referenced by MyNamespace.Tests.

How could this be done? I have not found documentation on creating a IsUsedBy that does not take a constant.

Sincerely,

Martin

Patrick from NDepend team
  • 13,237
  • 6
  • 61
  • 92
Martin Noreke
  • 4,066
  • 22
  • 34

1 Answers1

2

For matching dead assemblies, you don't need to count types but just to count assemblies using me:

warnif count > 0 
from a in JustMyCode.Assemblies where
  a.AssembliesUsingMe.Count() == 0
  select a

If you want to match a condition on types using an assembly you can write something like:

warnif count > 0 
from a in JustMyCode.Assemblies
let typesUser =  Application.Types.Using(a)
where typesUser.Count() == 0 ||
      typesUser.ParentNamespaces()
      .WithNameWildcardMatchNotIn("MyNamespace.Tests*").Count() == 0
select a

Notice how in this previous query we don't even iterate on typesUser (with a typesUser.Where(t => ...) ), but instead we use NDepend.API set methods like WithNameWildcardMatchNotIn().

Patrick from NDepend team
  • 13,237
  • 6
  • 61
  • 92
  • With a small change to the wildcard to be "*Test*" to catch all of the test projects (no standard naming convention), this worked as required. Thank you much. – Martin Noreke Jun 06 '12 at 16:40