Alex Rivera | Logout

INotifyPropertyChanging and validations: when do I raise PropertyChanging?

Asked 2008-10-04T05:53:57.537
11

INotifyPropertyChanged is fairly self explanatory and I think I'm clear on when to raise that one (i.e. when I've finished updating the values).
If I implement INotifyPropertyChanging I'm tending to raise the event as soon as I enter the setter or other method that changes the objects state and then continue with any guards and validations that may occur.

So I'm treating the event as a notification that the property may change but hasn't yet been changed, and might not actually finish changing successfully.

If consumers of the object are using this property (like let's say LINQ to SQL using the event for change tracking) should I be holding off and only raising the event once I have validated that the the values I've been given are good and the state of the object is valid for the change?

What is the contract for this event and what side effects would there be in subscribers?

Edit
Report

1 Answer

0

If you would like to avoid implementing INotifyPropertyChanged altogether, consider using Update Controls .NET instead. This eliminates almost all of the bookkeeping code.

answered 2008-12-30T13:02:10.250

Your Answer