I am trying to get a MethodInfo
object for the method:
Any<TSource>(IEnumerable<TSource>, Func<TSource, Boolean>)
The problem I'm having is working out how you specify the type parameter for the Func<TSource, Boolean>
bit...
MethodInfo method = typeof(Enumerable).GetMethod("Any", new[] { typeof(Func<what goes here?, Boolean>) });
Help appreciated.
You can create an extension method that does the work of retrieving all of the methods and filtering them in order to return the desired generic method.
Using the extension method above, you can write code similar to what you had intended:
There's no way of getting it in a single call, as you would need to make a generic type constructed of the generic parameter of the method (TSource in this case). And as it's specific to the method, you would need to get the method to get it and build the generic Func type. Chicken and egg issue heh?
What you can do though is to get all the Any methods defined on Enumerable, and iterate over those to get the one you want.