我的类中有一个属性,在set访问器中有很多逻辑:
private String text;
public String Text
{
get { return text; }
private set
{
// some actions with a value
value = value.Replace('a', 'b');
text = value;
}
}
Run Code Online (Sandbox Code Playgroud)
如何防止其他开发人员(甚至是我)更改此类中的字段而不是属性?
如果有人写这样的话:
public Test(String text)
{
this.text = text;
}
Run Code Online (Sandbox Code Playgroud)
它会打破我班级的逻辑!