Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rusith/urd
undo redo pattern for .NET
https://github.com/rusith/urd
Last synced: about 1 month ago
JSON representation
undo redo pattern for .NET
- Host: GitHub
- URL: https://github.com/rusith/urd
- Owner: rusith
- Created: 2015-12-31T15:23:02.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-12T11:46:29.000Z (over 7 years ago)
- Last Synced: 2024-04-24T04:15:14.793Z (7 months ago)
- Language: C#
- Homepage:
- Size: 228 KB
- Stars: 5
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# URD
#undo redo pattern for .Net applicationsthis is a basic undo and redo pattern for .NET applications.
in this pattern when you need an undo / redo able action you will need to warp that action in a using block.
as an example if you going to change a property```C#
using (new PropertyChange(Object, "Property", "Property changed "))
{
Object.Property="new value";
}
```
now the change you made to the "Property" property of the "Object" object is added to a drop out stack and the action can undo and redo any time .if you want an undoAble list change you can do it using same syntax
```C#
private void AddNewItem(List list,string item,bool undoAble)
{
using (undoAble?new ListChangeAddElement(list,item,"add new string to the string list"):null) //you can use a condition then you can minimize code
{
list.Add(item);
}
}
```Removing an Item
```C#
private void RemoveItem(list,item,bool undoAble)
{
using(undoAble?new ListChangeRemoveElement(list,item,list.IndexOf(item)," remove "+item+" from the string list"))
{
list.Remove(item);
}
}
```
so on.. (check the code)benefits of this pattern
* No need to change existing objects
* Low Memory usageif you wish to implement your own operation . only thing you need to do is create a class--> extend Change class and implement IUndoAble interface.