class Memento
{
private string state;
public Memento(string state)
{
this.State = state;
}
public string State { get => state; set => state = value; }
}
class Originator
{
private string state;
public Memento CreateMemento()
{
return new Memento(state);
}
public void SetMemento(Memento m)
{
this.state = m.State;
}
public void Show()
{
Console.WriteLine("State=" + state);
}
public string State { get => state; set => state = value; }
}
class Caretaker
{
private Memento memento;
public Memento Memento { get => memento; set => memento = value; }
}
class Program
{
static void Main(string[] args)
{
Originator o = new Originator();
o.State = "On";
o.Show();
Caretaker c = new Caretaker();
c.Memento = o.CreateMemento();
o.State = "Off";
o.Show();
o.SetMemento(c.Memento);
o.Show();
}
}