FieldBuilder.SetValue(Object, Object, BindingFlags, Binder, CultureInfo) 方法

定义

设置给定对象支持的字段的值。Sets the value of the field supported by the given object.

public:
 override void SetValue(System::Object ^ obj, System::Object ^ val, System::Reflection::BindingFlags invokeAttr, System::Reflection::Binder ^ binder, System::Globalization::CultureInfo ^ culture);
public override void SetValue (object? obj, object? val, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder? binder, System.Globalization.CultureInfo? culture);
public override void SetValue (object obj, object val, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Globalization.CultureInfo culture);
override this.SetValue : obj * obj * System.Reflection.BindingFlags * System.Reflection.Binder * System.Globalization.CultureInfo -> unit
Public Overrides Sub SetValue (obj As Object, val As Object, invokeAttr As BindingFlags, binder As Binder, culture As CultureInfo)

参数

obj
Object

在其上访问该字段的对象。The object on which to access the field.

val
Object

要分配给字段的值。The value to assign to the field.

invokeAttr
BindingFlags

指定所需绑定类型的 IBinder 的成员(例如,IBinder.CreateInstance、IBinder.ExactBinding)。A member of IBinder that specifies the type of binding that is desired (for example, IBinder.CreateInstance, IBinder.ExactBinding).

binder
Binder

一组使用反射启用绑定、参数类型强制和成员调用的属性。A set of properties and enabling for binding, coercion of argument types, and invocation of members using reflection. 如果活页夹为 null,则使用 IBinder.DefaultBinding。If binder is null, then IBinder.DefaultBinding is used.

culture
CultureInfo

特定区域性的软件首选项。The software preferences of a particular culture.

例外

不支持此方法。This method is not supported.

注解

此方法会将 val 参数分配给在上由此实例反映的字段 Object objThis method will assign the val parameter to the field reflected by this instance on Objectobj. 如果该字段为静态,则 obj 将被忽略。If the field is static, obj will be ignored. 对于非静态字段, obj 应为继承或声明该字段的类的实例。For non-static fields, obj should be an instance of a class that inherits or declares the field.

新值作为传递 ObjectThe new value is passed as an Object. 例如,如果该字段的类型为布尔 Object 值,则会传递一个具有适当布尔值的实例。For example, if the field's type is Boolean, an instance of Object with the appropriate Boolean value is passed. 设置该值之前,请 SetValue 检查用户是否具有访问权限。Before setting the value, SetValue checks to see if the user has access permission.

对于完全受信任的代码,将忽略访问限制。Access restrictions are ignored for fully-trusted code. Private 只要代码完全受信任,就可以使用反射来访问和调用构造函数、方法、字段和属性。Private constructors, methods, fields, and properties can be accessed and invoked using Reflection whenever the code is fully-trusted.

备注

当前不支持该方法。This method is currently not supported. 作为一种解决方法, FieldInfo 可通过反射完成类型并调用 SetValue 来设置字段的值,来检索。As a workaround, retrieve the FieldInfo by reflecting on the finished type and call SetValue to set the value of the field.

适用于