понедельник, 22 апреля 2013 г.

C#: Checking for null’s with monads


public static TResult With<tinput tresult="">
(this TInput o, Func<tinput tresult=""> evaluator)
where TResult : class
where TInput : class
{
    return (o == null) ? return null : evaluator(o);
}
Usage:
string postCode = this.With(x => person)
 .With(x => x.Address)
 .With(x => x.PostCode);

Комментариев нет:

Отправить комментарий