(using .Net 3.5) I have a routine that imports settings from an external datasource, after which I need to display a pseudo-log to the user detailing which properties have been updated. Usually I would track property updates through the property_changed events. However, when the value from the datasource happens to already equal the property value, then property_changed event never gets raised, even if the property set was called. But I still need to display such properties to the user as being “updated” from the datasource.
What is the common pattern here? Do I need another event (in addtion to property_changed) in my property setters- “property_attemptedset”?
Edit: So one suggestion is that I simply not do an equality check in the property setter, so that “property_changed” gets fired no matter what. But I’ve always been told to filter for actual value changes. Is that not best practice?
if you write your properties like this:
It should always fire the
PropertyChanged-event, even if the value is the same. You don’t need to fire any additional events for this.EDIT
in addition to your edit: Yes, it is considered best practice to check for actual value changes, but if your scenario needs to track non-value changes, I don’t see why you can’t change it. “Best practice” doesn’t mean “Break-this-rule-and-go-to-jail” thing right?
But in case these classes have any other observers, which also rely on the common PropertyChanged behavior, you can always extend the properties and throw another (custom) event like you mentioned: