I know of the error "The accessibility modifier of the set accessor must be more restrictive than the property or indexer". I also know the solution. Just not in this very specific case.
Consider this example:
internal virtual bool IsFocused
{
get
{
return isFocused;
}
protected set
{
isFocused = value;
}
}
private bool isFocused;
It shows the error. I just don't know why. How is "protected" not less accessible than internal? What would be the solution to this problem? I tried putting "internal protected" instead, without luck.
protected
allows an inherting class to access it whileinternal
does NOT -internal
restricts access to the assembly itself - see http://msdn.microsoft.com/en-us/library/7c5ka91b%28v=vs.80%29.aspxAs it turns out,
protected
is more accessible thaninternal
. Recall thatinternal
means "not visible outside of this assembly" (except throughInternalsVisibleTo
access, which makesinternal
look likepublic
), whereasprotected
means visible to all subclasses.@bobbymcr is entirely right in his analysis. The solution would be to mark property as
internal protected
. In C# that means that it would be accessible both to derived classes AND to all classes from current assembly.If you put
internal protected
to accessor method - that means that it is accessible to derived classes. But entire property is not, which causes the error. If you mark entire property asinternal protected
and accessor method asprotected
- everything is fine.Other option would be to introduce
protected
method that would be called in setter. Then you could mark entire property asinternal
and allow to override only that method.