Snapshot
When working with a mutable instance, it's often useful to keep a certain state of that object. This issue is usually solved by implementing IClonable
or using Serialization
(followed by Deserialization
).
This might be an issue, however, when that instance is one from a third-party library. I wrote a little library, called Snapshot, that uses the DLR to come up with a solution to this problem.
By default, it will map all public properties and fields to a dynamic object. This behaviour is configurable. You will end up with a dynamic object with the same public signature as the one you took a snapshot of.
var person = new Person("Steven", "Thuriot");
person.Age = 27;
var snapshot = person.TakeSnapshot();
person.Age = 28;
Console.WriteLine("Person age: {0}", person.Age);
Console.WriteLine("Snapshot age: {0}", snapshot.Age);
Output:
Person age: 28
Snapshot age: 27