Opentribe.Memento 0.1.8

Opentribe Memento

Opentribe Memento is a C# open source library which provide all you need to manage Undo/Redo feature in your programs.
The memento pattern is a software design pattern that provides the ability to restore an object to the previous state. In its original form, discribed by the “Gang or four” in the book “Design patterns : Elements of reusable object-oriented software”, the memento design patters was implemented in three objects. It is not the case in this implementation. I can say that the Opentribe Memento library does not implement strictly the pattern designed by the “Gang of four”.
For Patrick Soquet, creator of Key language, Apple Media Tools authoring tool and iShell authoring tool, the architecture of a software is deeply influenced by the language.
Followong this idea, I created the Opentribe Memento library which doesn’t strictly follow the memento design pattern, but achieves the same target of the design pattern using elegants features of c# language.

There is a newer version of this package available.
See the version list below for details.
Install-Package Opentribe.Memento -Version 0.1.8
dotnet add package Opentribe.Memento --version 0.1.8
<PackageReference Include="Opentribe.Memento" Version="0.1.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Opentribe.Memento --version 0.1.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

// Initialize the Memento
// First step is to initialize a Memento object. This object is the “Caretaker” in the memento design pattern.
public static Memento.Memento Caretaker { get; set; } = new Memento.Memento();

//Remember and change one attribute
//To remember the state of an object, you have to ask the Caretaker to remember each attributes of the object than you are free to modify these attributes.

Caretaker.Remember<MyObject, string>(AnObject, “MyStringAttribute”); // remember

AnObject.MyStringAttribute = “A new state”; // change attribute

Caretaker.Undo(); // restore the previous value

// Remember and change several attributes
// To remember the state of an object, you have to ask the Caretaker to remember each attributes of the object than you are free to modify these attributes.

Caretaker.Begin(); // start to remember
Caretaker.Remember<MyObject, string>(AnObject, “MyStringAttribute”); // remember first attribute
Caretaker.Remember<MyObject, int>(AnObject, “MyIntAttribute”); // remember second attribute
Caretaker.End(); // stop registering

AnObject.MyStringAttribute = “A new state”; // change first attribute
AnObject.MyIntAttribute = 123; // change second attribute

Caretaker.Undo(); // restores second and first attribute.

// Initialize the Memento
// First step is to initialize a Memento object. This object is the “Caretaker” in the memento design pattern.
public static Memento.Memento Caretaker { get; set; } = new Memento.Memento();

//Remember and change one attribute
//To remember the state of an object, you have to ask the Caretaker to remember each attributes of the object than you are free to modify these attributes.

Caretaker.Remember<MyObject, string>(AnObject, “MyStringAttribute”); // remember

AnObject.MyStringAttribute = “A new state”; // change attribute

Caretaker.Undo(); // restore the previous value

// Remember and change several attributes
// To remember the state of an object, you have to ask the Caretaker to remember each attributes of the object than you are free to modify these attributes.

Caretaker.Begin(); // start to remember
Caretaker.Remember<MyObject, string>(AnObject, “MyStringAttribute”); // remember first attribute
Caretaker.Remember<MyObject, int>(AnObject, “MyIntAttribute”); // remember second attribute
Caretaker.End(); // stop registering

AnObject.MyStringAttribute = “A new state”; // change first attribute
AnObject.MyIntAttribute = 123; // change second attribute

Caretaker.Undo(); // restores second and first attribute.

Release Notes

First release.

Dependencies

This package has no dependencies.

Version History

Version Downloads Last updated
0.2.1 250 11/26/2017
0.2.0 223 11/26/2017
0.1.9 190 11/25/2017
0.1.8 207 11/25/2017
0.1.7 182 11/24/2017
0.1.6 189 11/22/2017
0.1.5 203 11/3/2017
0.1.2 202 10/30/2017
0.1.1 191 10/30/2017
0.1.0 182 10/30/2017