Skip to content

Instantly share code, notes, and snippets.

@hadynz
Created July 7, 2014 09:49
Show Gist options
  • Save hadynz/f7db6c9669b1f4520952 to your computer and use it in GitHub Desktop.
Save hadynz/f7db6c9669b1f4520952 to your computer and use it in GitHub Desktop.
public static class EvalExtension
{
public static TResult Eval<T, TResult>(this T obj, Func<T, TResult> func) where T : class
{
return obj.Eval(func, default(TResult));
}
public static TResult Eval<T, TResult>(this T obj, Func<T, TResult> func, TResult defaultValue) where T : class
{
return obj == null ? defaultValue : func(obj);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment