Abstract class constructor (ARCH710)
Ce contenu n’est pas encore disponible dans votre langue.
Key dotnet.codequality.abstract-class-constructor · Severity warning · Category codequality
Abstract classes cannot be instantiated directly, so exposing a public or internal constructor is misleading. The constructor should be protected for derived types only.
Incorrect
Section titled “Incorrect”public abstract class Shape{ public Shape(string name) => Name = name; public string Name { get; }}Correct
Section titled “Correct”public abstract class Shape{ protected Shape(string name) => Name = name; public string Name { get; }}Mark abstract class constructors as protected (or private protected).