C# CodeAnalysis ProtectedAndInternal vs ProtectedOrInternal

Viewed 69

I'm unclear about the distinction between the Accessibility values ProtectedAndInternal and ProtectedOrInternal.

I found a reference stating ProtectedOrInternal maps to the source code construct protected internal.

But -- assuming that's correct -- what does it mean for something to be both protected and internal?

2 Answers

ProtectedOrInternal corresponds to protected internal:

The protected internal keyword combination is a member access modifier. A protected internal member is accessible from the current assembly or from types that are derived from the containing class. For a comparison of protected internal with the other access modifiers, see Accessibility Levels.

ProtectedAndInternal corresponds to private protected:

The private protected keyword combination is a member access modifier. A private protected member is accessible by types derived from the containing class, but only within its containing assembly. For a comparison of private protected with the other access modifiers, see Accessibility Levels.

It's a combination of both types of accesibility levels. Whether some object can be accessed from within the same assembly (internal) or can use the derived types (protected). They are not the same but can be used interchangeably

Related