Check that all types that has the attribute FooAttribute are declared in the namespace N1.N2*

Rule ND9909 Samples of Custom rules / Check Architecture

A sample rule to adapt to your need: enforces that all types tagged with a particular attribute are declared in a particular namespace.

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 types that has the attribute FooAttribute are declared in the namespace N1.N2*</Name>
// <Id>ND9909:ExplicitId9909</Id>

warnif count > 0 from t in 
  Application.Namespaces.WithNameWildcardMatchNotIn("N1.N2*").ChildTypes() 
  where 
    t.HasAttribute ("FooAttribute".AllowNoMatch())
select new {
   t,
   Debt = 10.ToMinutes().ToDebt(),
   Severity = Severity.High
}

//<Expl>
// The *{0}* has the attribute *FooAttribute* and thus should be declared in namespace *N1.N2* because *your reason*.
//</Expl>

//<Desc>
// A *sample rule to adapt to your need*: enforces that all types tagged
// with a particular attribute are declared in a particular namespace.
//</Desc>

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

Samples of Custom rules / Check Architecture: all 10 items