469,286 Members | 2,404 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,286 developers. It's quick & easy.

Undo/Redo

How to implement undo/redo technique in C#? The undo/redo are not only for
text changes, it also support previous action like creation of an object.
Nov 15 '05 #1
4 4527
Hi,

There is no support for such thing.
You'll have to do it by yourself.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"thanigai" <th**********@enventureonline.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
How to implement undo/redo technique in C#? The undo/redo are not only for
text changes, it also support previous action like creation of an object.

Nov 15 '05 #2
There's no "built-in" support, but take a look at the command pattern:

http://c2.com/cgi/wiki?CommandPattern
"thanigai" <th**********@enventureonline.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
How to implement undo/redo technique in C#? The undo/redo are not only for
text changes, it also support previous action like creation of an object.

Nov 15 '05 #3

"Philip Rieck" <st***@mckraken.com> wrote in message
news:eg**************@TK2MSFTNGP09.phx.gbl...
There's no "built-in" support, but take a look at the command pattern:

http://c2.com/cgi/wiki?CommandPattern
"thanigai" <th**********@enventureonline.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
How to implement undo/redo technique in C#? The undo/redo are not only for text changes, it also support previous action like creation of an object.



You can also read about the Command Pattern in the "GOF" book (i.e. "Design
Patterns by Gamma, Helm, Johnson, Vlissides")

--
Sam Gentile [C#/.NET MVP]
..NET Blog http://samgentile.com/blog/
Nov 15 '05 #4
I would agree. The "command pattern," as it's called, is probably what you
will have to use. However, the wiki mentions that you may have an explosion
of Command classes as a problem. Depending on your performance constraints,
you might be better off writing just a few "generic" command classes that
use reflection. So you might try something like:

#region Assumed
public interface ICommand {
void Do();
void Undo();
}
#endregion

#region Example
[Serializable]
public class PropertySetCommand : ICommand {
private object _Instance;
private System.Reflection.PropertyInfo _TargetProperty;
private object _OldValue;
private object _NewValue;
private object[] _Indeces;

public PropertySetCommand(object instance,
System.Reflection.PropertyInfo targetProperty, object oldValue, object
newValue, object[] indeces) {
_Instance = instance;
_TargetProperty = targetProperty;
_OldValue = oldValue;
_NewValue = newValue;
_Indeces = new object[indeces.Length];
Array.Copy(indeces, _Indeces, indeces.Length);
}

#region ICommand Members
public void Do() {
_TargetProperty.SetValue(_Instance, _NewValue, _Indeces);
}

public void Undo() {
_TargetProperty.SetValue(_Instance, _OldValue, _Indeces);
}
#endregion
}
#endregion

I'm not suggesting this as a perfect, or even good, solution. I'm just
saying that if you suddenly found yourself drowning in an endless sea of
slightly different command classes, using reflection might be an option. It
will, almost certainly, come at the expense of either performance or your
budget, though.

--
Max Guernsey, III
http://www.harbingersoftware.com

"Philip Rieck" <st***@mckraken.com> wrote in message
news:eg**************@TK2MSFTNGP09.phx.gbl...
There's no "built-in" support, but take a look at the command pattern:

http://c2.com/cgi/wiki?CommandPattern
"thanigai" <th**********@enventureonline.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
How to implement undo/redo technique in C#? The undo/redo are not only for text changes, it also support previous action like creation of an object.


Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jay | last post: by
reply views Thread by John Benson | last post: by
11 posts views Thread by Mad Joe | last post: by
3 posts views Thread by Teis Draiby | last post: by
1 post views Thread by Alan | last post: by
2 posts views Thread by Christian H | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.