I've been reading posts on this all day and none of them seem to match the situation I've got closely enough. I have a class with the following methods:
IQueryable<TBusinessContract> Query<TBusinessContract>(
Expression<Func<TBusinessContract, bool>> condition, params string[] children )
where TBusinessContract : BusinessContract;
IQueryable<TSubType> Query<TSuperType, TSubType>(
Expression<Func<TSubType, bool>> condition, params string[] children )
where TSuperType : BusinessContract
where TSubType : BusinessContract;
I want to get a MethodInfo for the first one. I've tried a number of different combinations and permutations and I either get null or an ambiguous match exception. I have come up with the following that is working but feels a bit kludgy.
MethodInfo queryMethod = Dal.GetType()
.GetMethods( BindingFlags.Public | BindingFlags.Instance )
.Where( mi => mi.Name == "Query" )
.Where( mi => mi.IsGenericMethod )
.Where( mi => mi.GetGenericArguments().Length == 1 )
.SingleOrDefault();
Is this the best I can do or am I missing something? I'm using .NET 4.5.