Mono Class Library: System.Reflection.FieldInfo Overview | Members

System.Reflection.FieldInfo.SetValue Method

Assigns the specified value to the field that is reflected by the current instance and contained in the specified object. [Edit]

[System.Diagnostics.DebuggerStepThrough]
public void SetValue (object obj, object value)

Parameters

obj
The object whose field value will be set. If the field is static, obj is ignored. For non-static fields, obj is required to be an instance of a class that inherits or declares the field. [Edit]
value
A object that contains the value to assign to the field contained by obj . [Edit]
value
Documentation for this section has not yet been entered. [Edit]

Permissions

TypeReason
System.Security.Permissions.ReflectionPermission [Edit] Requires permission to access non-public members of a type in loaded assemblies. See System.Security.Permissions.ReflectionPermissionFlag.MemberAccess.

Exceptions

TypeReason
ArgumentException

The field reflected by the current instance is declared neither directly in obj nor in any class from which obj derives.

value is not assignment-compatible with the type of the field reflected by the current instance.

[Edit]
FieldAccessExceptionThe field reflected by the current instance is non-public, and the caller does not have permission to access non-public members. [Edit]
System.Reflection.TargetExceptionThe field reflected by the current instance is non-static, and obj is null . [Edit]

Remarks

Before setting the value, the system verifies that the user has access permission. If the user does not have access permission, a FieldAccessException is thrown. [Edit]

Requirements

Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0