I'd like to create an internal auto-property:
internal bool IP { get; protected internal set; }
I thought it would be possible to make the setter protected
or protected internal
- but I always get the error accessibility modifier must be more restrictive than the property. Isn't that the case? Private
does not help me, here.
EDIT:
The question is: How do I implement an auto-property with a internal getter and a protected setter?
protected: The type or member can be accessed only by code in the same class , or in a class that is derived from that class . internal: The type or member can be accessed by any code in the same assembly, but not from another assembly.
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.
public. The code is accessible for all classes. private. The code is only accessible within the same class.
It's effectively protected
or internal
, not and. It's accessible both by derived classes and types in the same assembly. It's a common misconception to think protected internal
means accessible only to derived classes in the same assembly.
At the .NET level, there are two similar but distinct access levels:
"protected internal" in C# means FamilyOrAssembly; there's no modifier for FamilyAndAssembly.
So, your protected internal
setter is less restrictive than the internal
overall property. What you could do is:
protected internal bool IP { internal get; set; }
But then your setter is less restricted than your getter, which is odd...
Another (somewhat equivalent) alternative is:
internal bool IP { get; set; } protected void SetIP(bool ip) { this.IP = ip; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With