AArnott/ImmutableObjectGraph — pull request #1 by StanislawSwierc (2013-02-20 00:37:42+00:00)
Title: Remove defaultX parameters from the With method

With method was using defaultX parameters to find out when the user wants
to set a property to a default value. This could lead to serious bugs in
methods which use With without explicitly checking all the parameters
before the call. For example, even though the method below is quite
simple it will fail when the skin thickness is equal to one.

public Fruit DecreaseSkinThickness()
{
return fruit.With(skinThickness: this.SkinThickness - 1);
}

var apple = Fruit.Default.With(color: "red", skinThickness: 1);
var apple1 = apple.DecreaseSkinThickness();
Debug.Assert(apple1.SkinThickness == 0); // Fail!

In order to reduce the risk of bugs described above I propose
WithParameter struct which can completely replace defaultX parameters.
This is a struct parameter so it can be put on the stack thus the GC
pressure is low. The new With method is 9% slower but this seems a fair
price for the correctness.