Is there any way to enforce the rest of my class to access the property setter rather than the backing field? Consider the following clumsy code:
public class Brittle
{
private string _somethingWorthProtecting;
public string SomethingWorthProtecting
{
get { return _somethingWorthProtecting; }
set
{
_somethingWorthProtecting = value;
ReallyNeedToDoThisEverTimeTheValueChanges();
}
}
public void OhDearWhatWasIThinking()
{
_somethingWorthProtecting = "Shooting myself in the foot here, aren't I?";
}
}
As far as I know, C# does not provide any mechanism to prevent the class developer from making this mistake. (Auto-properties are clearly not an option in this situation.) Is there a design pattern or practice that can help safeguard against such inadvertant end-arounds?