Check that all methods that call Foo.Fct1() also call Foo.Fct2(Int32)

Rule ND9907 Samples of Custom rules / Check Architecture

A sample rule to adapt to your need: enforces that a method calling a particular method must also call another particular method.

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 methods that call Foo.Fct1() also call Foo.Fct2(Int32)</Name>
// <Id>ND9907:ExplicitId9907</Id>

warnif count > 0 from m in Application.Methods where 
   m.IsUsing ("Foo.Fct1()".AllowNoMatch()) &&
  !m.IsUsing ("Foo.Fct2(Int32)".AllowNoMatch())
select new {
   m,
   Debt = 10.ToMinutes().ToDebt(),
   Severity = Severity.High
}

//<Expl>
// The *{0}* calls *Foo.Fct1()* and thus, should also call *Foo.Fct2(Int32)* because *your reason**.
//</Expl>

//<Desc>
// A *sample rule to adapt to your need*: enforces that a method calling a
// particular method must also call another particular method.
//</Desc>

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

Samples of Custom rules / Check Architecture: all 10 items