i'm having a bit of confusion with property accessors.
I'd like to have an internal property with its set accessor only accessible to derived classes.
something like this
internal [internalClass] MyProperty
{
get {return _prop;}
protected set {_prop = value;}
}
when i do this the compiler complains.
MSDN, when discussing this particular error suggests changing the set
access modifier to private
which is not where i want this to go.
it looks like Protected Internal
should be an option here however using this modifier gives the same error
I have a feeling i'm missing some basic understanding of access modifiers.
thanks
Neither protected
nor protected internal
is more restrictive than internal
. Both would let derived types from a different assembly access the setter but not the getter. protected internal
gives access to the union of protected
and internal
, not the intersection. (There is an access level representing the intersection in the CLR, but it's not exposed by C#.)
You might be best off using a private setter and a protected SetMyProperty
method which just calls the private setter, if that matches what you want to achieve.
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