Alex Rivera | Logout

What is the best practice to check if an object is changed?

Asked 2010-01-15T12:43:38.833
23

I need to know how do you check if an object is changed. Basically I need something like a property that is named TrackChanges, when I set it true once and if any data within this object is "changed", a method on the same object (IsObjectChanged) can return true.

Did you ever needed such a thing and how did you solve it? I do not want to invent the wheel if there is already a best-practice for such scenario?

I was thinking to clone the object before I call TrackChange=true, in its setter. And when I call IsObjectChanged() By using reflection I will compare all the public field values of it with the cloned copy. I am not sure if it is a good way.

Any advices?

thanks, burak ozdogan

Edit
Report

1 Answer

1

Why don't you create a List and put your first object in, then you can compare it to the current object by using a simple comparison.

As above you can use INotifyPropertyChanged to see what properties have changed in your object.

answered 2010-01-15T12:49:18.627

Your Answer