0

I am struggeling in making properties of classes defined as internal only setable by children (protected).

For clearity here an example:

internal class Foo
{
     internal int Bar { get; protected set; }

     internal Foo(int bar)
     {
         this.Bar = bar;
     }

     internal void Baz()
     {
         this.Bar++;
     }
}

This results in an error, which says, that the access of Bar needs to be more restrictive than the set-Accessor (which is correct, since protected allows access for classes outside of the assembly).

The only workaround I have here, is to declare Bar as public, but this is not, what I actually intended. I probably need to modify Bar by some other methods (maybe even by children) than the constructor, so readonly wouldn’t work for me.

Is there any possibility to make properties of an internal class internal accessible for read and internal and protected accessible for write?

Edit: I am sorry, I just realized, that this question is basically the same as mine. I somehow did not find it before.

Sebastian Werk
  • 1,568
  • 2
  • 17
  • 30

0 Answers0