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.

Types too big

I use extension methods to collect several functionality for e.g. framework types as string. Each Extension-Class is typically  spread across several files and partial to keep overview and maintainability. NDepend analyses on assembly basis and therefor cannot know about my tricks. But I can put some knowledge into the query:

warnif count > 0 from t in JustMyCode.Types where
   t.NbLinesOfCode > 500 && !t.Name.EndsWith("Extensions")
   orderby t.NbLinesOfCode descending
   select new {
    t, t.NbLinesOfCode,
    t.Methods, t.Fields