Check that all types that derive from Foo, also implement IFoo

Rule ND9908 Samples of Custom rules / Check Architecture

A sample rule to adapt to your need: enforces that all classes deriving from a particular base class also implement a particular interface.

How to fix

This is a sample rule, there is nothing to fix as is.

CQLinq source

This rule is written in CQLinq, C# LINQ over the NDepend code model. It ships with every new NDepend project: you can read it, adapt it, or use it as a starting point for your own custom rules.

// <Name>Check that all types that derive from Foo, also implement IFoo</Name>
// <Id>ND9908:ExplicitId9908</Id>

warnif count > 0 from t in Application.Types where 
   t.DeriveFrom ("Foo".AllowNoMatch().MatchType()) &&
  !t.Implement ("IFoo".AllowNoMatch().MatchType())
select new {
   t,
   Debt = 5.ToMinutes().ToDebt(),
   Severity = Severity.High
}

//<Expl>
// The *{0}* derives from *Foo* and should also implement *IFoo* because *your reason*.
//</Expl>

//<Desc>
// A *sample rule to adapt to your need*: enforces that all classes deriving
// from a particular base class also implement a particular interface.
//</Desc>

//<HowToFix>
// This is a *sample rule*, there is nothing to fix *as is*.
//</HowToFix>

Samples of Custom rules / Check Architecture: all 10 items