this enables you to use the copyUpdateExpression to get clones of immutable style c# classes with properties set
A concrete example
using With;
...
public class CustomerChangeHandler
{
// start with initializing the copy update expression once (main cost is around parsing expressions)
private static readonly IPreparedCopy<Customer, int, string, IEnumerable<string>> CopyUpdate =
LensBuilder<Customer>.Of(m => m.Id).And(m => m.Name).And(m => m.Preferences)
.BuildPreparedCopy();
public void Handle()
{
// fetch customer, say:
var customer = new Customer(id:1, name:"Johan Testsson");
// change that customer with new values:
var change = CopyUpdate.Copy(customer, NextId(), "Erik Testsson", new []{"Swedish fish"});
// ...
}
}
In order to be able to create prepared copy expressions for more properties the easiest way is to expose lenses:
this enables you to use the copyUpdateExpression to get clones of immutable style c# classes with properties set
A concrete example