ServiceStack/ServiceStack — pull request #752 by mmertsock (2013-06-28 20:27:57+00:00)
Title: PopulateWithNonDefaultValues - handle nullables

For nullable properties, treat null as the default value, and any
non-null, including the default value of the underlying value type, as
non-default. Allows using PopulateWithNonDefaultValues to populate both
true and false values if the source property is a nullable boolean, for
example.

Detailed example:

class Source { bool? BoolValue { get; set; } }
class Destination { bool BoolValue { get; set; } }

This has always worked, because of the `x != null` check in `nonDefaultPredicate`:

dest = new Destination { BoolValue = true };
dest.PopulateWithNonDefaultValues(new Source { BoolValue = null });
Assert.That(dest.BoolValue, Is.True);

This has always worked, because in `nonDefaultPredicate`, `x` is auto-boxed as
Boolean object with value of true, so `x != null` and `ReflectionUtils.GetDefaultValue`
will return `false`.

dest = new Destination { BoolValue = false };
dest.PopulateWithNonDefaultValues(new Source { BoolValue = true });
Assert.That(dest.BoolValue, Is.True);

Here is what we want to change: when a nullable bool has a value of false, we were
expecting this to be treated as "non default" since it's not null. The current code however
will treat a nullable boolean with a value of false (or a nullable int with value of zero, etc.)
as a "default" value and refuse to update the destination object.

var dest = new Destination { BoolValue = true };
dest.PopulateWithNonDefaultValues(new Source { BoolValue = false });
Assert.That(dest.BoolValue, Is.False); // currently fails

We changed this behavior by passing the `PropertyType` info into the `nonDefaultPredicate`
lambda, and using that type info in `ReflectionUtils.GetDefaultValue` instead of using `x.GetType()`.
Basically, if `x` is a nullable bool, `x.GetType()` will actually give you the `Boolean` type
object instead of `Nullable`, thus `GetDefaultValue` will return `false` instead of `null`.

See [comments and answers in this post](http://stackoverflow.com/q/374651/795339) for more details on why `GetType()` doesn't work well with nullables.

**Question:** is there any concern about changing the behavior of `PopulateWithNondefaultValues` in this way?