Check that the assembly Asm1 is only using the assemblies Asm2, Asm3 or System.Runtime

Rule ND9903 Samples of Custom rules / Check Architecture

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

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 assembly Asm1 is only using the assemblies Asm2, Asm3 or System.Runtime</Name>
// <Id>ND9903:ExplicitId9903</Id>

warnif count > 0 from a in Application.Assemblies where 
  ( !a.IsUsing ("Asm2".AllowNoMatch().MatchAssembly()) ||
    !a.IsUsing ("Asm3".AllowNoMatch().MatchAssembly()) ||
    !a.IsUsing ("System.Runtime".MatchAssembly()) ||
     a.AssembliesUsed.Count() != 3) // Must not be used more than 3 assemblies 
&& 
  (a.Name == @"Asm1")
select new { 
   a, 
   a.AssembliesUsed,
   Debt = 30.ToMinutes().ToDebt(),
   Severity = Severity.High
}

//<Expl>
// The *{0}* is using the *{1}* but should only use the assemblies *Asm2*, *Asm3* or *System.Runtime*.
//</Expl>

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

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

Samples of Custom rules / Check Architecture: all 10 items