ReflectorTryGetField(Object, String, Object, ReflectionWays) Method

Tries to get the instance field of an object represented by the specified fieldName.

Definition

Namespace: KGySoft.Reflection
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 8.1.0
C#
public static bool TryGetField(
	Object instance,
	string fieldName,
	out Object?? value,
	ReflectionWays way = ReflectionWays.Auto
)

Parameters

instance  Object
An instance whose field is about to be retrieved.
fieldName  String
The name of the field to get.
value  Object
When this method returns with result, then this parameter contains the value of the field.
way  ReflectionWays  (Optional)
The preferred reflection way. TypeDescriptor way is not applicable for fields. This parameter is optional.
Default value: Auto.

Return Value

Boolean
, if the field could be read; , if a field with name fieldName could not be found.

Remarks

fieldName can refer public and non-public fields.

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

If way is Auto, then this method uses the DynamicDelegate way.

See Also