I have a class which is serialized to and from an XML file when the user decided to open or save. I'm trying to add the typical functionality where when they try to close the form with un-saved changes the form warns them and gives them the option of saving before closing.
I've added a HasUnsavedChanges
property to my class, which my form checks before closing. However, it's a little annoying that my properties have changed from something like this ..
public string Name
{
get;
set;
}
to this...
private string _Name;
public string Name
{
get
{
return _Name;
}
set
{
this._Name = value;
this.HasUnsavedChanges = true;
}
}
Is there a better way to track changes to an instance of a class? For example is there some standard way I can "hash" an instance of a class into a value that I can use to compare the most recent version with the saved version without mucking up every property in the class?