This may sound stupid but I cannot get the MethodInfo of Queryable.Join(...). I want to get it because of How to use a Type variable in a generic method call (C#)
It has 2 available method signatures and I want to get the one without IEqualityComparer, so I need to specify Type[] in GetMethod.
I wrote something like
MethodInfo joinMethod = typeof( Queryable ).GetMethod( "Join", new Type[] { typeof(IEnumerable<>), typeof(Expression<Func<>>), typeof(Expression<Func<>>), typeof(Expression<Func<>>)});
but it doesn’t work. I’m unable to specify the types in generics above, because they are passed as Type from outside (and this is why I need this reflection).
Can anyone tell me how? Thanks!
Working with generics and reflection can be a bit tedious. Your best bet (to keep things simple) is to use
GetMethodsand filter by what you are looking for.Given that, the
MethodInfois not invokable at this point. You need to make a generic version of it by usingjoinMethod.MakeGenericMethod(/*type array*/). In your case, you would need to use 4 types: TOuter, TInner, TKey, TResult.Now you can use
genericJoinMethodas you’d expect to.As far as I know, that is the only way to do it if you don’t know the types at compile-time.
EDIT:
Given your comment, I think it should look something like this: