reactiveui/ReactiveUI — pull request #739 by bradphelan (2014-10-15 08:07:33+00:00)
Title: Provide a virtual method Validate() on ReactiveObject

This Validate method is just a simple hook. It makes no assumptions about the method of validation you wish to employ other than you would wish to perform validation before sending out property changed events.

My use case is that I have a view model and I do something like this

this.WhenAnyValue(p=>p.ConfigurationData.Height)
.Where(_ => this.IsValid )
.Subscribe( DoSomethingDangerous );

IsValid is a boolean property on my viewmodel implemented by my custom validation. It is not part of the pull request. However IsValid must be calculated before the property changed event is delivered. I could subscribe to PropertyChanged to implement the validation but then there is a race condition with the validator subscription and the WhenAnyValue subscription.

Other alternative is to add a new event __PropertyBeforeChangedEvent__ which is broadcast before the __PropertyChangedEvent__. __WhenAnyValue__ subscribes to the __PropertyChangedEvent__ and the validator can subscribe to the __PropertyBeforeChangedEvent__. Note this new event is not the __PropertyChangingEvent__. __PropertyChangingEvent__ is delivered before the property is set. __PropertyBeforeChangedEvent__ would be sent out after the property is set but before the __PropertyChangedEvent__