c# - On clicking CancelBtn cancel changes -


i have in program custom property grid, properties bindable viewmodel. in property grid there 2 buttons - savebtn , editbtn. user edit properties in property grid. when savebtn clicked, properties must saved in database. if user wants edit properties, clicks editbtn , before saving properties database(savebtn clicked), should appear new window, user chooses reason of modification of properties. on window there 3 buttons - exitwithsavingtodatabase, exitwithoutsavingtodatabase , cancel.

if user chooses cancel, changes should canceled. properties in viewmodel have new values. my question - how can reset properties old values??? thinking of reloading properties database, if there better solution, can without using database?

there number of approaches:

  1. one of you've mentioned - throw away modified object , new 1 unchanged properties store.
  2. memento/caretaker pattern. memento object, takes snapshot of original values, , caretaker object, can rollback changes, using snapshot, stored in memento (also, may consider undo/redo evolution of pattern).
  3. you modify copy of object, , if user wants save changes, should apply property values copy original. requires object-to-object mappers (e.g. automapper), manual copying of property values error prone.

Comments