A bit of this odd ...
Suppose I have the following class:
public class Wibble
{
public string Foo {get;set;}
public string Bar {get;set;}
}
This class is used in the process when the values of Foo and Bar are updated or changed. However, after a certain point in the process, I want to “block” the instance to prevent any changes. So the question is, what is the best way to do this?
The kind solution will look something like this:
public class Wibble
{
private string _foo;
private string _bar;
public bool Locked {get; set;}
public string Foo
{
get
{
return this._foo
}
set
{
if (this.Locked)
{
throw new ObjectIsLockedException()
}
this._foo = value;
}
}
public string Bar
{
get
{
return this._bar
}
set
{
if (this.Locked)
{
throw new ObjectIsLockedException()
}
this._bar = value;
}
}
}
However, this seems a little inelegant.
, , , . Wibble , , . , , . "" , , .