samedi 30 novembre 2019

find MethodInfo of Queryable.Where where the second parameter takes a Func<,>

I'd like to have the MethodInfo of the following method.

static public IQueryable<TSource> Where<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, Boolean>> predicate)

My way to do this is:

Type tQueryable = Type.GetType("System.Linq.IQueryable`1, System.Linq.Expressions");

Type tExpression = Type.GetType("System.Linq.Expressions.Expression`1, System.Linq.Expressions");
Type tFunc = Type.GetType("System.Func`2");
Type tExpressionWithGeneric = tExpression.MakeGenericType(tFunc);

var method = typeof(Queryable).GetMethod("Where", new Type[] { tQueryable, tExpressionWithGeneric });

The retrieving of types works fine but finally method is always null. I don't like to walk thru the array that GetMethods delivers.

Any ideas?





Aucun commentaire:

Enregistrer un commentaire