Check that the namespace N1.N2 is only using the namespaces N3.N4, N5 or System
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>
Open in the interactive Rules Explorer · All default rules
Samples of Custom rules / Check Architecture: all 10 items
- Check that the assembly Asm1 is not using the assembly Asm2 ND9901
- Check that the namespace N1.N2 is not using the namespace N3.N4.N5 ND9902
- Check that the assembly Asm1 is only using the assemblies Asm2, Asm3 or System.Runtime ND9903
- Check that the namespace N1.N2 is only using the namespaces N3.N4, N5 or System ND9904
- Check that AsmABC is the only assembly that is using System.Collections.Concurrent ND9905
- Check that only 3 assemblies are using System.Collections.Concurrent ND9906
- Check that all methods that call Foo.Fct1() also call Foo.Fct2(Int32) ND9907
- Check that all types that derive from Foo, also implement IFoo ND9908
- Check that all types that has the attribute FooAttribute are declared in the namespace N1.N2* ND9909
- Check that all synchronization objects are only used from the namespaces under MyNamespace.Sync ND9910