All rules
CA1813Performance Enabled by default: No

Avoid unsealed attributes

Avoid unsealed attributes

Microsoft docs

Description

.NET provides methods for retrieving custom attributes. By default, these methods search the attribute inheritance hierarchy. For example, System.Attribute.GetCustomAttribute searches for the specified attribute type or any attribute type that extends the specified attribute type. Sealing the attribute eliminates the search through the inheritance hierarchy, and can improve performance.

Cause

A public type inherits from System.Attribute, is not abstract, and is not sealed (NotInheritable in Visual Basic).

How to fix violations

To fix a violation of this rule, seal the attribute type or make it abstract.

Example

#pragma warning disable CA1813
// The code that's violating the rule is on this line.
#pragma warning restore CA1813

When to suppress

It is safe to suppress a warning from this rule. Suppress only if you are defining an attribute hierarchy and cannot seal the attribute or make it abstract.

Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0