Check that the namespace N1.N2 is only using the namespaces N3.N4, N5 or System

Rule ND9904 Samples of Custom rules / Check Architecture

A sample rule to adapt to your need: enforces that a particular namespace is only using a particular set of namespaces.

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 only using the namespaces N3.N4, N5 or System</Name>
// <Id>ND9904:ExplicitId9904</Id>

warnif count > 0 from n in Application.Namespaces where 
  ( !n.IsUsing("N3.N4".AllowNoMatch().MatchNamespace()) ||
    !n.IsUsing("N5".AllowNoMatch().MatchNamespace()) ||
    !n.IsUsing("System".MatchNamespace()) ||
     n.NamespacesUsed.Count() != 3) // Must not be used more than 3 assemblies 
                // AsmCe = Efferent Coupling for assembly
&& 
  (n.Name == @"N1.N2")
select new { 
   n, 
   n.NamespacesUsed,
   Debt = 30.ToMinutes().ToDebt(),
   Severity = Severity.High
}

//<Expl>
// The *{0}* is using the *{1}* but should only use the assemblies *N3.N4, N5* or *System*.
//</Expl>

//<Desc>
// A *sample rule to adapt to your need*: enforces that a particular
// namespace **is only using** a particular set of namespaces.
//</Desc>

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

Samples of Custom rules / Check Architecture: all 10 items