Skip to content

M_Cyjb_Reflection_MethodBaseUtil_PowerDelegate_1

CYJB edited this page Mar 20, 2024 · 13 revisions

MethodBaseUtil.PowerDelegate 方法 (MethodBase, Type, Object)

使用指定的第一个参数,创建用于表示指定静态或实例方法的指定类型的委托。

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

语法

C#

public static Delegate? PowerDelegate(
	this MethodBase method,
	Type delegateType,
	Object? firstArgument
)

参数

 

method
Type: System.Reflection.MethodBase
描述委托要表示的静态或实例方法的 MethodInfo
delegateType
Type: System.Type
要创建的委托类型。
firstArgument
Type: System.Object
如果是实例方法(非构造函数),则作为委托要绑定到的对象; 否则将作为方法的第一个参数。

返回值

Type: Delegate
指定类型的委托,表示访问指定的静态或实例方法。如果无法绑定,则为 null

备注

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

Exceptions

 

异常 条件
ArgumentNullException methodnull
ArgumentNullException delegateTypenull
ArgumentException delegateType 不是委托类型。
MethodAccessException 调用方无权访问 method

Remarks

支持参数的强制类型转换,参数声明可以与实际类型不同。

参见

Reference

MethodBaseUtil 类
PowerDelegate 重载
Cyjb.Reflection 命名空间

Clone this wiki locally