ReflectorSetField(Type, String, Object, ReflectionWays) Method

Sets the static field of a Type represented by the specified fieldName.

Definition

Namespace: KGySoft.Reflection
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.0.0
C#
public static void SetField(
	Type type,
	string fieldName,
	Object? value,
	ReflectionWays way = ReflectionWays.Auto
)

Parameters

type  Type
The Type the static field belongs to.
fieldName  String
The name of the field to be 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

fieldName can refer public and non-public fields.

If you already have a FieldInfo instance use the SetField(Object, FieldInfo, Object, ReflectionWays) method for better performance.

If you are not sure whether a field with the specified fieldName exists, then you can use the TrySetField methods instead.

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

See Also