I recently did something at work where you defined a method using lambda, which then got an internal object. You can also use strings or pass to MethodInfo, but the first one is not type safe (and typos are a big risk), and the latter is not very elegant.
Basically, I had such a method (this is not an exact method, it is a bit more advanced):
public void SetRequest(Request req, Expression<Func<Service, Func<long, IEnumerable<Stuff>>> methodSelector);
The key here is the “Expression” thing, this allows you to “choose” a method similar to this:
SetRequest(req, service => service.SomeMethodTakingLongReturningStuffs);
The method selector turns into an expression tree from which you can extract different bits of data. I don’t remember exactly what the resulting tree looks like, it also depends on how your lambdas look.
Skurmedel Feb 22 '10 at 21:41 2010-02-22 21:41
source share