UndoableBase's CopyState()

UndoableBase's CopyState()

Old forum URL: forums.lhotka.net/forums/t/3349.aspx


SunilKutty posted on Wednesday, August 08, 2007

I was going through UndoableBase's CopyState() method, it uses reflection to make a deep copy of objects and stores into a stack.

I was wondering why not use binary serialization to make the deep copies and store into a stack and use reflection to restore state.

Am I missing something?

RockfordLhotka replied on Wednesday, August 08, 2007

Binary serialization always returns a new instance of the object on deserialization. If you used that, every time you called CancelEdit() you'd have to unbind and rebind all your objects to the UI - which would make n-level undo useless for support of data binding.

The code in UndoableBase is able to restore the object's previous state "in-place" so the object reference remains valid and no rebinding is required - and this technique then works with data binding.

Copyright (c) Marimer LLC