I currently have a setter method which looks like this:
private string _a;
public virtual string A
{
get { return _a; }
set
{
if (_a!= value)
{
if (this.OnPropertyChanging("A", _a, value))
{
var previousValue = _a;
_a = value;
this.OnPropertyChanged("A", previousValue, value);
}
}
}
}
I have implemented this with help from Dr Wily’s Apprentice (http://stackoverflow.com/a/8578507/981225), with a custom Changing handler that keeps track of the old and current value, as well as the ability to set the Changing event as ‘Cancelled’, such that the PropertyChange will not occur.
This works perfectly. However, we have hundreds of properties and this is a lot of code the duplicate.
I have used Castle’s DynamicProxy in the past, to avoid having to write ‘OnPropertyChanged(“A”)’.
How can I implement the logic within this setter, as part of the Proxy’s Intercept method? Is it possible? Thank you.
Maybe I’m a bit late, but I came across a similar task in the Linq-To-SharePoint model. I sketched some code if some one’s still wondering.