All rules
CA1852Performance Enabled by default: No

Seal internal types

Seal internal types

Microsoft docs

Description

When a type isn't accessible outside its assembly and has no subtypes within its containing assembly, it can be safely sealed. Sealing types can improve performance. For more information, see Analyzer Proposal: Seal internal/private types].

If you apply System.Runtime.CompilerServices.InternalsVisibleToAttribute to the assembly that's being analyzed, this rule doesn't flag types that aren't marked as sealed by default, because a field may be used by a friend assembly. To analyze the assembly anyway, see Configure code to analyze.

Cause

A type that's not accessible outside its assembly and has no subtypes within its containing assembly is not marked sealed (NotInheritable in Visual Basic).

How to fix violations

Mark the type as sealed (NotInheritable in Visual Basic).

Example

internal class C
{ }

internal sealed class C
{ }

When to suppress

It's safe to suppress a warning if performance isn't a concern.

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