I am looking for a visibility modifier for attributes of an inner class that would allow the outer class to modify/set a value but external classes could only get/read the value.
public class Outer {
public class Inner {
// I want this to be editable by Outer instances
// but read-only to other external classes.
public string attribute;
}
}
You don’t have an access modifier for that, but you can get away with something like this:
Basically you taking advantage of the fact that nested classes have access to
privatemembers of the enclosing class and providing for the enclosing class a proxy to set theattributeproperty for a givenInnerinstance. Since external classes do not have access to this proxy you satisfied your requirement.