Aller au contenu

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.

public class JsonReportFormatter : IReportFormatter
{
public string Format(Report report) => JsonSerializer.Serialize(report);
}
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.