Export (0) Print
Expand All

FieldInfo.SetValue Method (Object, Object, BindingFlags, Binder, CultureInfo)

When overridden in a derived class, sets the value of the field with the specified constraints on type conversion.

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

public abstract void SetValue(
	Object obj,
	Object value,
	BindingFlags invokeAttr,
	Binder binder,
	CultureInfo culture
)

Parameters

obj
Type: System.Object
The object whose field value will be set.
value
Type: System.Object
The value to assign to the field.
invokeAttr
Type: System.Reflection.BindingFlags
The type of binding that is desired.
binder
Type: System.Reflection.Binder
An object that enables the binding of this field to obj and the coercion of value to FieldType. If binder is null, then Type.DefaultBinder is used.
culture
Type: System.Globalization.CultureInfo
The culture that controls the coercion of obj to FieldType.

ExceptionCondition
FieldAccessException

The field is not accessible.

TargetException

The obj parameter is null and the field is an instance field.

ArgumentException

The field does not exist on the object.

-or-

The value parameter cannot be converted and stored in the field.

MethodAccessException

The member is invoked late-bound through mechanisms such as Type.InvokeMember.

In Silverlight, only accessible fields can be set using reflection.

This method will assign value to the field reflected by this instance on obj. If the field is static, obj will be ignored. For nonstatic fields, obj should be an instance of a class that inherits or declares the field. The new value is passed as an Object. For example, if the field is of type Boolean, the new value must be boxed as an instance of Object.

Platform Notes

Silverlight for Windows Phone Silverlight for Windows Phone

 SetValue throws an ArgumentNullException exception instead of a TargetException exception when obj is null.

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft