Beispiel #1
0
 /// <summary>
 /// 根据实参参数类型推断当前泛型方法定义的类型参数,
 /// 并返回表示结果构造方法的 <see cref="System.Reflection.MethodInfo"/> 对象。
 /// </summary>
 /// <param name="method">要进行类型参数推断的泛型方法。</param>
 /// <param name="types">泛型方法的实参参数数组。</param>
 /// <returns>一个 <see cref="System.Reflection.MethodInfo"/> 对象,
 /// 表示通过将当前泛型方法定义的类型参数替换为根据 <paramref name="types"/>
 /// 推断得到的元素生成的构造方法。</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>
 /// <exception cref="System.ArgumentException">不能从 <paramref name="types"/> 推断得到类型参数。</exception>
 /// <exception cref="System.ArgumentException">根据 <paramref name="types"/>
 /// 推断出来的类型参数中的某个元素不满足为当前泛型方法定义的相应类型参数指定的约束。</exception>
 public static MethodInfo MakeGenericMethodFromParams(this MethodInfo method, params Type[] types)
 {
     Type[] args = GenericArgumentsInferences(method, types);
     if (args == null)
     {
         throw ExceptionHelper.CannotInferGenericArguments("types", method);
     }
     return(method.MakeGenericMethod(args));
 }