Testing objects for changes
Posted
by David Veeneman
on Stack Overflow
See other posts from Stack Overflow
or by David Veeneman
Published on 2010-03-26T15:34:52Z
Indexed on
2010/03/26
15:43 UTC
Read the original article
Hit count: 345
c#
|comparison
I have an application that needs to determine whether a user has made a change to an object. So, when the object is first loaded, I create a deep copy (using serialization/deserialization) and save the copy to a separate field. The copy becomes myCurrentObject
, and the original becomes myOriginalObject
.
Now I need to test myCurrentObject
for changes, which I plan to do by comparing it to myOriginalObject
. All I need is a boolean
result indicating whether any changes have been made. I have already determined that a simple hashcode comparison won't work. GetHashCode()
generates different results for the two objects, even when there are no changes.
I am getting ready to write a method to do a property-by-property comparison, but before I do, I thought I would check to see if there is a simpler and more reusable way to test myCurrentObject
to see if it has changed from myOriginalObject
.
Any suggestions? Thanks for your help.
© Stack Overflow or respective owner