private static MethodInfo GetEnumerableMethod(string methodName, Type[] types)
{
return (from m in typeof(Enumerable).GetMethods()
where m.Name.EqualsIgnoreCase(methodName) && m.IsGenericMethod
let parameters = m.GetParameters()
where parameters.Length == 2 && parameters.All(x => x.ParameterType.IsGenericType)
&& parameters[0].ParameterType.GetGenericTypeDefinition() == typeof(IEnumerable<>)
&& parameters[1].ParameterType.GetGenericTypeDefinition() == typeof(Func<,>)
select m.MakeGenericMethod(types)).FirstOrDefault();
}