Thursday, February 26, 2009

Fast Clone

Ever had to make a in memory copy of a simple object? You then have to copy each property or create an IClonable implentation. Just like the simple reflection form you can use reflection to create a fast clone.
Just call the static method FastClone.Clone:

Customer c = new Customer
Id = Guid.NewGuid(),
Name = "Frank",
Age = 31,
Married = true

Customer c2 = (Customer)FastClone.Clone(c, "Id");

Optionally properties can be given to exclude from the clone.
You can download the source of FastClone here.