Skip to content

M_Cyjb_Reflection_MethodInfoUtil_MakeGenericMethodFromArgumentTypes

CYJB edited this page Mar 20, 2024 · 13 revisions

MethodInfoUtil.MakeGenericMethodFromArgumentTypes 方法 (MethodInfo, Type[])

根据实参参数类型推断当前泛型方法定义的类型参数,并返回表示结果封闭构造方法的 MethodInfo 对象。

Namespace: Cyjb.Reflection
Assembly: Cyjb (in Cyjb.dll) Version: 1.0.23+7750dd8e971297c5fa962a3bee37fb78f72793f6

语法

C#

public static MethodInfo MakeGenericMethodFromArgumentTypes(
	this MethodInfo method,
	params Type[] types
)

参数

 

method
Type: System.Reflection.MethodInfo
要进行类型参数推断的泛型方法定义。
types
Type: System.Type[]
泛型方法的实参参数数组。

返回值

Type: MethodInfo
一个 MethodInfo 对象,表示通过将当前泛型方法定义的类型参数替换为根据 types 推断得到的元素生成的封闭构造方法。

备注

在 Visual Basic 和 C# 中,这个方法可以当成为类型MethodInfo的实例方法来调用。在采用实例方法语法调用这个方法时,请省略第一个参数。请参考 扩展方法 (Visual Basic)扩展方法 (C# 编程指南) 获取更多信息。

Exceptions

 

异常 条件
InvalidOperationException 当前 MethodInfo 不表示泛型方法定义。 也就是说,IsGenericMethodDefinition 返回 false
ArgumentNullException methodnull
ArgumentNullException typesnull
ArgumentException 不能从 types 推断得到类型参数。
ArgumentException 根据 types 推断出来的类型参数中的某个元素不满足为当前泛型方法定义的相应类型参数指定的约束。

参见

Reference

MethodInfoUtil 类
MakeGenericMethodFromArgumentTypes 重载
Cyjb.Reflection 命名空间

Clone this wiki locally