ReflectorSetField(Object, FieldInfo, Object, ReflectionWays) Method

Sets a field represented by the specified FieldInfo.

Definition

Namespace: KGySoft.Reflection
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.0.0
C#
public static void SetField(
	Object? instance,
	FieldInfo field,
	Object? value,
	ReflectionWays way = ReflectionWays.Auto
)

Parameters

instance  Object
An instance whose field is about to be set. This parameter is ignored for static fields.
field  FieldInfo
The field to set.
value  Object
The value to set.
way  ReflectionWays  (Optional)
The preferred reflection way. TypeDescriptor way is not applicable for fields. This parameter is optional.
Default value: Auto.

Remarks

If way is Auto, then the DynamicDelegate way will be used.

  Tip

To preserve the changes of a mutable value type embed it into a variable of Object type and pass it to the instance parameter of this method.

  Note

To set the field explicitly by dynamically created delegates use the FieldAccessor class.

See Also