Say you are trying to read this property
var town = Staff.HomeAddress.Postcode.Town;
Somewhere along the chain a null could exist. What wo
I came up with the same solution as Ani's some time ago, see this blog post for details. While elegant, it's very inefficient...
var town = Staff.NullSafeEval(s => s.HomeAddress.Postcode.Town, "(N/A)");
A better solution IMHO is the one suggested in this CodeProject article:
string town = Staff.With(s => s.HomeAddress)
.With(a => a.Postcode)
.With(p => p.Town);
The only thing I don't like with this solution is the name of the extension method, but it can easily be changed...