FieldInfo.SetValueDirect(TypedReference, Object) 方法

定义

重要

此 API 不符合 CLS。

符合 CLS 的替代方案
System.Reflection.FieldInfo.SetValue(Object, Object, BindingFlags, Binder, CultureInfo)

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

public:
 virtual void SetValueDirect(TypedReference obj, System::Object ^ value);
[System.CLSCompliant(false)]
public virtual void SetValueDirect (TypedReference obj, object value);
public virtual void SetValueDirect (TypedReference obj, object value);
[<System.CLSCompliant(false)>]
abstract member SetValueDirect : TypedReference * obj -> unit
override this.SetValueDirect : TypedReference * obj -> unit
abstract member SetValueDirect : TypedReference * obj -> unit
override this.SetValueDirect : TypedReference * obj -> unit
Public Overridable Sub SetValueDirect (obj As TypedReference, value As Object)

参数

obj
TypedReference

一个 TypedReference 结构,该结构封装指向某位置的托管指针以及该位置可存储的类型的运行时表示形式。A TypedReference structure that encapsulates a managed pointer to a location and a runtime representation of the type that can be stored at that location.

value
Object

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

实现

属性

例外

调用方需要公共语言规范 (CLS) 的替代项,但改为调用此方法。The caller requires the Common Language Specification (CLS) alternative, but called this method instead.

注解

备注

从 .NET Framework 2.0 Service Pack 1 开始,此方法可用于访问非公共成员(如果调用方已 ReflectionPermission 使用 ReflectionPermissionFlag.RestrictedMemberAccess 标志授予),并且如果非公共成员的授予集限制为调用方的授予集或其子集,则可使用此方法访问非公共成员。Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public members if the caller has been granted ReflectionPermission with the ReflectionPermissionFlag.RestrictedMemberAccess flag and if the grant set of the non-public members is restricted to the caller's grant set, or a subset thereof. (参阅 反射的安全注意事项) (See Security Considerations for Reflection.)

若要使用此功能,应用程序应面向 .NET Framework 3.5 或更高版本。To use this functionality, your application should target the .NET Framework 3.5 or later.

适用于