FieldInfo.SetValueDirect Method

Sets the value of the field supported by the given object.

This method is not CLS-compliant.   The CLS-compliant alternative is SetValue(Object,Object,BindingFlags,Binder,CultureInfo).

Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)

[CLSCompliantAttribute(false)] 
public virtual void SetValueDirect (
	TypedReference obj,
	Object value
)
/** @attribute CLSCompliantAttribute(false) */ 
public void SetValueDirect (
	TypedReference obj, 
	Object value
)
CLSCompliantAttribute(false) 
public function SetValueDirect (
	obj : TypedReference, 
	value : Object
)
Not applicable.

Parameters

obj

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

The value to assign to the field.

Exception typeCondition

NotSupportedException

The caller requires the Common Language Specification (CLS) alternative, but called this method instead.

NoteNote:

Starting with the , this method can be used to access non-public members if the caller has been granted ReflectionPermission with the ReflectionPermissionFlag.ReflectionEmit 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.)

To use this functionality, your application should target the . For more information, see The .NET Framework 3.5 Architecture.

  • ReflectionPermission  for accessing non-public fields when the grant set of the non-public members is restricted to the caller's grant set, or a subset thereof. Associated enumeration: System.Security.Permissions.ReflectionPermissionFlag.RestrictedMemberAccess
  • ReflectionPermission  for accessing non-public fields regardless of their grant set. Associated enumeration: ReflectionPermissionFlag.MemberAccess
  • ReflectionPermission  when invoked late-bound through mechanisms such as Type.InvokeMember. Associated enumeration: ReflectionPermissionFlag.MemberAccess.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show: