I have a POCO that is updated every N seconds. The problem I have is that not all properties may have changed since the last update.
I need to know which properties have changed since the last update so I can log the changes. I could do this by keeping a copy of the POCO from the previous update and performing a comparison each time and then maybe firing an event for each property change.
Does anyone have a better solution that I could use here?
http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx this is the standard way that plays nice with databinding.
saving the state of each property as an “old” value every time you do your update is necessary in the situation where you only want to detect properties which have actually different values than last time – for example, if you don’t want a property that changed from 5 to 3 to 7 back to 5 since last update.
if you don’t care about this distinction, and don’t want to use propertychanged, you can give each property a bool value they you set to true in the setter, and set them to false every time you update.
you can create a GetProperty/SetProperty mechanic – you call these functions in the setters/getters, and you can then save the actual data and any metadata about it in any way you want under the hood. However this is not really POCO any more.