Skip to content

M_Cyjb_Reflection_FieldInfoUtil_PowerDelegate__1_1

CYJB edited this page Mar 20, 2024 · 13 revisions

FieldInfoUtil.PowerDelegate(TDelegate) 方法 (FieldInfo, Object)

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

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

语法

C#

public static TDelegate PowerDelegate<TDelegate>(
	this FieldInfo field,
	Object? firstArgument
)
where TDelegate : Delegate

参数

 

field
Type: System.Reflection.FieldInfo
描述委托要表示的静态或实例字段的 FieldInfo
firstArgument
Type: System.Object
如果是实例字段,则作为委托要绑定到的对象;否则将作为字段的第一个参数。

类型参数

 

TDelegate
要创建的委托的类型。

返回值

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

备注

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

Exceptions

 

异常 条件
ArgumentNullException fieldnull
MethodAccessException 调用方无权访问 field

Remarks

如果委托具有返回值,则认为是获取字段,否则认为是设置字段;会忽略不需要的参数。 支持参数的强制类型转换,参数声明可以与实际类型不同。

参见

Reference

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

Clone this wiki locally