CA2222: Do not decrease inherited member visibility
Visual Studio 2010
TypeName | DoNotDecreaseInheritedMemberVisibility |
CheckId | CA2222 |
Category | Microsoft.Usage |
Breaking Change | Non Breaking |
You should not change the access modifier for inherited members. Changing an inherited member to private does not prevent callers from accessing the base class implementation of the method. If the member is made private and the type is unsealed, inheriting types can call the last public implementation of the method in the inheritance hierarchy. If you must change the access modifier, either the method should be marked final or its type should be sealed to prevent the method from being overridden.
The following example shows a type that violates this rule.
using System; namespace UsageLibrary { public class ABaseType { public void BasePublicMethod(int argument1) {} } public class ADerivedType:ABaseType { // Violates rule: DoNotDecreaseInheritedMemberVisibility. // The compiler returns an error if this is overridden instead of new. private new void BasePublicMethod(int argument1){} } }