hago una pequeña modificación de la consulta lambda.
Cuando el tipo de parámetro si genérica que debe hacer que, al igual que:
agrego pi.ParameterType.GetGenericTypeDefinition()
y
(m.ReturnType.IsGenericType ? m.ReturnType.GetGenericTypeDefinition() : m.ReturnType) == returnType)
De esta manera, el método de trabajo muy fino
MethodInfo foo1 = (from m in t.GetMethods(BindingFlags.Public | BindingFlags.Static)
where m.Name == name
&& m.GetGenericArguments().Length == genericArgTypes.Length
&& m.GetParameters().Select(pi => pi.ParameterType.IsGenericType ? pi.ParameterType.GetGenericTypeDefinition() : pi.ParameterType).SequenceEqual(argTypes) &&
(returnType==null || (m.ReturnType.IsGenericType ? m.ReturnType.GetGenericTypeDefinition() : m.ReturnType) == returnType)
select m).FirstOrDefault();
if (foo1 != null)
{
return foo1.MakeGenericMethod(genericArgTypes);
}
return null;
Ejemplo:
Con la modificación del método que pueda llamar esta extensión método
public static IQueryable<T> FilterCulture<T>(this Table<T> t, IDatabaseFilter filter)
Con mi nuevo ayudante como esto
var QueryableExpression = MethodInfoHelper.GetGenericMethod(typeof(LinqFilterExtension), "FilterCulture", new Type[] { rowType }, new Type[] { typeof(Table<>), typeof(IDatabaseFilter) }, typeof(IQueryable<>));
La firma de mi ayudante es
public static MethodInfo GetGenericMethod(Type t, string name, Type[] genericArgTypes, Type[] argTypes, Type returnType)
que se está perdiendo un tipo de retorno en sus definiciones de métodos. – Ray
de hecho, ya no, gracias. –