NDepend is a tool that offers a wide range of features to let developers analyze a .NET code base. It comes with about 200 built in rules. But there are a few default rules that do not fit “my rules”. This blog post shows how to customize one and even more important why.

Avoid namespaces with few types

I observed that the original rule outputs an unnecessary line for namespace {} because of the compiler generated classes (caused by linq queries).


Here is my fixed rule to skip “0 types“ in the result:

warnif count > 0 from n in JustMyCode.Namespaces
let types = n.ChildTypes.Where(t => !t.IsGeneratedByCompiler)
  types.Count() < 5 &&
  types.Count() > 0
  orderby types.Count() ascending
select new { n, types }