A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1047 below:

CA1047: Do not declare protected members in sealed types (code analysis) - .NET

Property Value Rule ID CA1047 Title Do not declare protected members in sealed types Category Design Fix is breaking or non-breaking Non-breaking Enabled by default in .NET 9 As suggestion Cause

A public type is sealed (NotInheritable in Visual basic) and declares a protected member or a protected nested type. This rule does not report violations for Finalize methods, which must follow this pattern.

Rule description

Types declare protected members so that inheriting types can access or override the member. By definition, you cannot inherit from a sealed type, which means that protected methods on sealed types cannot be called.

The C# compiler emits warning CS0628 instead of CA1047 for this situation.

How to fix violations

To fix a violation of this rule, change the access level of the member to private, or make the type inheritable.

When to suppress warnings

Do not suppress a warning from this rule. Leaving the type in its current state can cause maintenance issues and does not provide any benefits.

Configure code to analyze

Use the following option to configure which parts of your codebase to run this rule on.

You can configure this option for just this rule, for all rules it applies to, or for all rules in this category (Design) that it applies to. For more information, see Code quality rule configuration options.

Include specific API surfaces

You can configure which parts of your codebase to run this rule on, based on their accessibility, by setting the api_surface option. For example, to specify that the rule should run only against the non-public API surface, add the following key-value pair to an .editorconfig file in your project:

dotnet_code_quality.CAXXXX.api_surface = private, internal

Note

Replace the XXXX part of CAXXXX with the ID of the applicable rule.

Example

The following example shows a type that violates this rule.

public sealed class SealedClass
{
    protected void ProtectedMethod(){}
}
Public NotInheritable Class BadSealedType
    Protected  Sub MyMethod
    End Sub
End Class

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4