-
Type:
Task
-
Resolution: Fixed
-
Priority:
Unknown
-
Affects Version/s: None
-
Component/s: LINQ3
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Use lambda expressions to specify methods for which we need to get the MethodInfo. This sometimes (but not always) makes for slightly longer lines than before, but it is much clearer than the previous approach.
For example, where we used to find the MethodInfo for the Queryable.Where method like this:
__where = new Func<IQueryable<object>, Expression<Func<object, bool>>, IQueryable<object>>(Queryable.Where).Method.GetGenericMethodDefinition();
we now instead write:
__where = ReflectionInfo.Method((IQueryable<object> source, Expression<Func<object, bool>> predicate) => source.Where(predicate));
Note that ReflectionInfo.Method takes a single argument: a lambda expression.
In this example the parameters to lambda expression are:
(IQueryable<object> source, Expression<Func<object, bool>> predicate)
and the body of the lamba expression is:
source.Where(predicate)
The body "looks" exactly like a "use" of the Queryable.Where method we want the MethodInfo for, because it IS a use. So it's obvious what method we are talking about. The MethodInfo itself can be extracted from the body of the lambda expression.
A very similar approach can also be used to get PropertyInfos and ConstructorInfos.