In my opinion, the current answers, including the accepted one, are far more complicated than necessary. If you have a type T
that you can use at compile time, you can get the MethodInfo
like so:
Func<IEnumerable<T>, Func<T, bool>, IEnumerable<T>> whereDelegate = Enumerable.Where;
MethodInfo whereMethodInfo = whereDelegate.Method;
As an extra bonus, this is strongly typed. It will compile only if the Enumerable.Where
can be resolved, as opposed to anything that looks for a string "Where"
: that would compile just fine if you accidentally type "Wehre"
instead, but would fail at runtime.