I am trying to get return the correct "Where" extension method using reflection, in order to build a custom Expression. I have tried several ways but the closest I get, throws an exception: "An unhandled exception of type 'System.Reflection.AmbiguousMatchException' occurred in mscorlib.dll"
I know this is because there are two Where methods defined in the Enumrable class - but how can I return the Where method which using only just a predicate of
Func<T, bool>.
What I have at the moment is:
var collectionType = typeof(TSub);
Type tIEnumerable = typeof(IEnumerable<>).MakeGenericType(collectionType);
MethodInfo methodInfo =
typeof(Enumerable)
.GetMethod("Where")
.MakeGenericMethod(collectionType);
I have also tried (this one returns null):
MethodInfo methodWhere = typeof(Enumerable).GetMethod("Where", new[] { typeof(TSub )});
and (also returns null)
MethodInfo methodWhere = typeof(Enumerable).GetMethod("Where", new[] { collectionType })
and (this one returns the same Ambiguous Exception)
MethodInfo methodWhere = typeof(Enumerable).GetMethod("Where", BindingFlags.Public | BindingFlags.Static)
Could anyone help at all please?
Thanks