Maybe there is more

Michel Perfetti, has taken my little Maybe thingie and gone a lot further,

by using expression tree re-writting he has made it possible to express this:

string code = licensePlate.Maybe(lp => lp.Car)
.Maybe(c => c.Owner)
.Maybe(o => o.Address)
.Maybe(a => a.PostCode);

which is NULL safe but very cumbersome like this:

string code = licensePlate.Maybe2(lp => lp.Car.Owner.Address.PostCode);

which is much cleaner and still NULL safe. 

Michel does this by declaring Maybe2 to take an Expression, rather than a Func i.e. it has this signature: public static V Maybe2<T, V>(this T t, Expression<Func<T, V>> expression)

Then he cracks open the expression and rewrites it to do each property access inside a call to Maybe.

Nice stuff Michel.

UPDATE: Sorry for originally getting your last name wrong Michel, and thanks Matthieu for pointing it out!