JetBrains Rider 2022.2 Help

Code Inspection: Member can be made private (private accessibility)

JetBrains Rider is smart enough to determine where a particular class member is actually being used. If it isn’t used outside the type or derived types, JetBrains Rider will offer to mark the member as private. If the member is used in derived classes too, JetBrains Rider will offer to mark it as protected.

Note that these recommendations need to be considered before being automatically applied. After all, you may be creating a public API, or you may be making types intended to be accessed in non-standard ways (for example, reflection). In this case, constraining visibility might not be a good idea. If necessary, you can always suppress the inspection.

In contrast to the similar solution-wide inspection that also detects unused public members in non-nested types, this local inspection will only notify you about public members in non-public nested types, which are not used in the parent type. This can indicate one of the two problems:

  • The public member is intended to be private. In this case, you can apply the quick-fix that JetBrains Rider suggests.

  • The public member is intended to be used in the parent class but not used there. In this case, the member cannot be a part of a public API and probably hides some not implemented functionality.

Last modified: 08 March 2021