Wednesday, August 8, 2007

Interesting Undo/Redo solution

A few weeks ago i found a very peculiar Undo/Redo solution here .

The way it was written surprised me. It even took me 2 or 3 minutes to get the idea how the code works :).

All the magic is hidden inside a UndoRedo class. The idea is that instead of creating your variables directly, you wrap them with UndoRedo class like this:


readonly UndoRedo name = new UndoRedo();
public string Name
{
get { return name.Value; }
set { name.Value = value; }
}



This solution is very interesting, but, from my perspective, it asks too much from the programmer. To use this UndoRedo mechanism you would require to rewrite all your classes, which needs capabality of UndoRedo.

What is more, you could not make TextBox undoable, without overriding the TextBox class. And of course we know, that some classes in M$ field are for some mysterious reason sealed, so you can not inherit.

But overall, the solution is interesting, and it does work :)

No comments: