Sealed class (ARCH712)
Ce contenu n’est pas encore disponible dans votre langue.
Key dotnet.codequality.sealed-class · Severity info · Category codequality
Sealing classes that are not designed for inheritance clarifies intent, prevents unintended derivation, and lets the JIT optimize method calls.
Incorrect
Section titled “Incorrect”public class JsonReportFormatter : IReportFormatter{ public string Format(Report report) => JsonSerializer.Serialize(report);}Correct
Section titled “Correct”public sealed class JsonReportFormatter : IReportFormatter{ public string Format(Report report) => JsonSerializer.Serialize(report);}Add sealed to classes that are not intended to be derived from.