converting a .net Func<T> to a .net Expression<Func<T>>
Going from a lambda to an Expression is easy using a method call... public void GimmeExpression(Expression<Func<T>> expression) { ((MemberExpression)expression.Body).Member.Name; // "DoStuff" } public void SomewhereElse() { GimmeExpression(() => thing.DoStuff()); } But I would like to turn the Func in to an expression, only in rare cases... public void ContainTheDanger(Func<T> dangerousCall) { try { dangerousCall(); } catch (Exception e) { // This next line does not work... Expression<Func<T>> DangerousExpression = dangerousCall; var nameOfDanger = ((MemberExpression)dangerousCall.Body).Member