Add another example of the memento pattern

This commit is contained in:
Petrutiu Mihai
2016-06-23 21:03:26 +03:00
parent 37151a23c7
commit 05709db77e
7 changed files with 175 additions and 1 deletions

View File

@@ -0,0 +1,33 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MememntoPattern.EmployeeSerialized
{
/// <summary>
/// Originator
/// </summary>
public class Employee
{
public string Name { get; set; }
public string Address { get; set; }
public List<string> Phones { get; set; }
public EmployeeMemento Save()
{
return new EmployeeMemento(JsonConvert.SerializeObject(this));
}
public void Revert(EmployeeMemento memento)
{
Employee newEmployee = JsonConvert.DeserializeObject<Employee>(memento.SerializedEmployee);
Name = newEmployee.Name;
Address = newEmployee.Address;
Phones = newEmployee.Phones;
}
}
}