Check that all types that derive from Foo, has a name that ends up with Foo
A sample rule to adapt to your need: enforces that all classes deriving from a particular class are named with a particular suffix.
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 derive from Foo, has a name that ends up with Foo</Name>
// <Id>ND9915:ExplicitId9915</Id>
warnif count > 0 from t in Application.Types where
t.DeriveFrom ("Foo".AllowNoMatch().MatchType()) &&
!t.NameLike (@"Foo$")
select new {
t,
t.NbLinesOfCode,
Debt = 5.ToMinutes().ToDebt(),
Severity = Severity.Medium
}
//<Expl>
// The *{0}* derives from *Foo* and thus, its name should end up with *Foo*.
//</Expl>
//<Desc>
// A *sample rule to adapt to your need*: enforces that all classes deriving
// from a particular class are named with a particular suffix.
//</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 / Custom Naming Conventions: all 2 items
- Check that all types that derive from Foo, has a name that ends up with Foo ND9915
- Check that all namespaces begins with CompanyName.ProductName ND9916