Skip to content

Gendarme.Rules.Performance.AvoidUnsealedConcreteAttributesRule(2.10)

Sebastien Pouliot edited this page Feb 9, 2011 · 3 revisions

AvoidUnsealedConcreteAttributesRule

Assembly: Gendarme.Rules.Performance
Version: 2.10

Description

This rule fires if an attribute is defined which is both concrete (i.e. not abstract) and unsealed. This is a performance problem because it means that System.Attribute.GetCustomAttribute has to search the attribute type hierarchy for derived types. To fix this either seal the type or make it abstract.

Examples

Bad example:

[AttributeUsage (AttributeTargets.All)]
public class BadAttribute : Attribute {
}

Good example (sealed):

[AttributeUsage (AttributeTargets.All)]
public sealed class SealedAttribute : Attribute {
}

Good example (abstract and sealed):

[AttributeUsage (AttributeTargets.All)]
public abstract class AbstractAttribute : Attribute {
}
[AttributeUsage (AttributeTargets.All)]
public sealed class ConcreteAttribute : AbstractAttribute {
}

Notes

  • Before Gendarme 2.0 this rule was named AvoidUnsealedAttributesRule.
Clone this wiki locally