Attribute classes should be sealed

Rule ND1310 Design

.NET methods fetching custom attributes (like System.Attribute.GetCustomAttribute()) explore the attribute inheritance hierarchy by default. Sealing the attribute removes that search, potentially enhancing performance.

How to fix

Seal the attribute type or make it abstract.

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>Attribute classes should be sealed</Name>
// <Id>ND1310:AttributeClassesShouldBeSealed</Id>

warnif count > 0 from t in Application.Types where 
  t.IsAttributeClass && 
 !t.IsSealed && 
 !t.IsAbstract && 
  t.IsPublic
select new {
   t, 
   t.NbLinesOfCode,
   Debt = 2.ToMinutes().ToDebt(),
   Severity = Severity.Medium
} 

//<Expl>
// To potentially enhance the performance of .NET 
// methods designed for custom attributes, it is 
// advisable to seal the attribute *{0}*.
//</Expl>

//<Desc>
// .NET methods fetching custom attributes (like
// *System.Attribute.GetCustomAttribute()*) explore the attribute inheritance
// hierarchy by default. Sealing the attribute removes that search,
// potentially enhancing performance.
//</Desc>

//<HowToFix>
// Seal the attribute type or make it abstract.
//</HowToFix>

Design: all 16 items