Check that the namespace N1.N2 is not using the namespace N3.N4.N5

Rule ND9902 Samples of Custom rules / Check Architecture

A sample rule to adapt to your need: warns if a particular namespace uses another particular namespace.

Generate such a rule for namespaces A and B by right-clicking the Dependency Matrix cell (B in row, A in column) or the Dependency Graph arrow from A to B, then clicking Generate a code rule that warns if this dependency exists. Adapt the generated rule to your needs.

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 the namespace N1.N2 is not using the namespace N3.N4.N5</Name>
// <Id>ND9902:ExplicitId9902</Id>

warnif count > 0 from n in Application.Namespaces where 
  n.IsUsing ("N3.N4.N5".AllowNoMatch().MatchNamespace()) &&
  (n.Name == @"N1.N2")
select new {
   n,
   Debt = 30.ToMinutes().ToDebt(),
   Severity = Severity.High
}

//<Expl>
// The *{0}* shouldn't use the namespace *N3.N4.N5* because *put your reason*.
//</Expl>

//<Desc>
// A *sample rule to adapt to your need*: warns if a particular namespace
// uses another particular namespace.
//
// Generate such a rule for namespaces **A** and **B** by right-clicking the
// *Dependency Matrix* cell (**B** in row, **A** in column) or the
// *Dependency Graph* arrow from **A** to **B**, then clicking
// **Generate a code rule that warns if this dependency exists**.
// Adapt the generated rule to your needs.
//</Desc>

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

Samples of Custom rules / Check Architecture: all 10 items