M_Cyjb_TypeUtil_PowerDelegate - CYJB/Cyjb GitHub Wiki
使用指定的第一个参数,创建用于表示指定静态或实例成员的指定类型的委托。
Namespace: Cyjb
Assembly: Cyjb (in Cyjb.dll) Version: 1.0.23+7750dd8e971297c5fa962a3bee37fb78f72793f6
C#
public static Delegate? PowerDelegate(
this Type type,
string name,
Type delegateType,
Object? firstArgument,
BindingFlags flags = BindingFlags.Default
)
- type
- Type: System.Type
要创建委托的类型。 - name
- Type: System.String
要创建委托的构造函数、方法、属性或字段成员的名称。 - delegateType
- Type: System.Type
要创建的委托类型。 - firstArgument
- Type: System.Object
如果是实例成员(非构造函数),则作为委托要绑定到的对象; 否则将作为方法的第一个参数。 - flags (Optional)
- Type: System.Reflection.BindingFlags
指示如何搜索成员的枚举值,默认会搜索全部公共成员。
Type: Delegate
指定类型的委托,表示访问指定的静态或实例成员。如果无法绑定 name, 则为 null
。
在 Visual Basic 和 C# 中,这个方法可以当成为类型Type的实例方法来调用。在采用实例方法语法调用这个方法时,请省略第一个参数。请参考 扩展方法 (Visual Basic) 或 扩展方法 (C# 编程指南) 获取更多信息。
异常 | 条件 |
---|---|
ArgumentNullException |
type 为 null 。 |
ArgumentNullException |
delegateType 为 null 。 |
ArgumentException | delegateType 不是委托类型。 |
ArgumentNullException |
name 为 null 。 |
MethodAccessException | 调用方无权访问 name。 |
如果是实例方法(非构造函数),需要将实例对象作为委托的第一个参数。 支持参数的强制类型转换,参数声明可以与实际类型不同。