public static IntPtr MakeGenericMethod(MethodInfo method, Type[] typeArgs)
{
if (method == null)
throw new ArgumentNullException("method");
if (typeArgs == null)
throw new ArgumentNullException("typeArgs");
if (!method.IsGenericMethodDefinition)
throw new ArgumentException("The method is not a generic method definition", "method");
var typeParams = method.GetGenericArguments();
if (typeParams.Length != typeArgs.Length)
throw new ArgumentException("An invalid amount of type arguments was specified", "typeArgs");
return method.MakeGenericMethod(typeArgs).MethodHandle.Value;
}