/// <summary> /// 根据给定的类型数组推断泛型方法的类型参数。 /// </summary> /// <param name="method">要推断类型参数的泛型方法。</param> /// <param name="types">实参参数数组。</param> /// <returns>如果成功推断泛型方法的类型参数,则为类型参数数组; /// 如果推断失败,则为 <c>null</c>。</returns> /// <exception cref="System.InvalidOperationException"> /// 当前 <see cref="System.Reflection.MethodBase"/> 不表示泛型方法定义。 /// 也就是说,<see cref="System.Reflection.MethodBase.IsGenericMethodDefinition "/> /// 返回 <c>false</c>。</exception> /// <exception cref="System.ArgumentNullException"><paramref name="method"/> 为 <c>null</c>。</exception> /// <exception cref="System.ArgumentNullException"><paramref name="types"/> 为 <c>null</c>。</exception> public static Type[] GenericArgumentsInferences(this MethodBase method, params Type[] types) { ExceptionHelper.CheckArgumentNull(method, "method"); ExceptionHelper.CheckArgumentNull(types, "types"); if (method.IsGenericMethodDefinition) { ParameterInfo[] parameters = method.GetParameters(); return(GenericArgumentsInferences(method, parameters, types)); } else { throw ExceptionHelper.NotGenericMethodDefinition(method, "GenericArgumentsInferences"); } }