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.

Static fields should be prefixed with a ’s_'

I use underdashes for instance fields and therefor I have a custom rule for static fields. They tend to look even more scary (and that’s what they should) if prefixed with ‘s’. So here is my rule:

warnif count > 0 from f in Application.Fields where
  !f.NameLike (@"^_") &&
   f.IsStatic &&
  !f.IsLiteral &&
  !f.IsGeneratedByCompiler &&
  !f.IsSpecialName &&
select new { f, f.SizeOfInst }