Skip to content

Gendarme.Rules.Performance.AvoidUnsealedConcreteAttributesRule(2.10)

Sebastien Pouliot edited this page Jan 15, 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.

Feedback

Note that this page was autogenerated (1/15/2011 12:27:16 PM) based on the xmldoc comments inside the rules source code and cannot be edited from this wiki. Please report any documentation errors, typos or suggestions to the Gendarme Google Group. Thanks!

Clone this wiki locally