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.
public static bool TrySetField(
Object instance,
string fieldName,
bool ignoreCase,
Object? value,
ReflectionWays way = ReflectionWays.Auto
)Public Shared Function TrySetField (
instance As Object,
fieldName As String,
ignoreCase As Boolean,
value As Object,
Optional way As ReflectionWays = ReflectionWays.Auto
) As Booleanpublic:
static bool TrySetField(
Object^ instance,
String^ fieldName,
bool ignoreCase,
Object^ value,
ReflectionWays way = ReflectionWays::Auto
)static member TrySetField :
instance : Object *
fieldName : string *
ignoreCase : bool *
value : Object *
?way : ReflectionWays
(* Defaults:
let _way = defaultArg way ReflectionWays.Auto
*)
-> bool 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 way is Auto, then the DynamicDelegate way will be used, except when the .NET Standard 2.0 version of the KGySoft.CoreLibraries assembly is referenced and the field is read-only or belongs to a value type (struct), in which case the SystemReflection way will be used.