ReflectorTrySetIndexedMember(Object, Object, ReflectionWays, Object) Method

Tries to set the value of an indexable object. It can be either an array or an object with default members (indexed properties).

Definition

Namespace: KGySoft.Reflection
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.0.0
C#
public static bool TrySetIndexedMember(
	Object instance,
	Object? value,
	ReflectionWays way,
	params Object?[] indexParameters
)

Parameters

instance  Object
An instance to be set.
value  Object
The value to set.
way  ReflectionWays
The preferred reflection way. TypeDescriptor way is not applicable here. This parameter is ignored for arrays.
indexParameters  Object
The index parameters.

Return Value

Boolean
, if the indexed member could be set; , if a matching property or array setter could not be found.

Remarks

This method ignores explicitly implemented interface properties.

  Note

If a matching indexed property could be found and the invocation itself has thrown an exception, then this method also throws an exception instead of returning .

If you already have a PropertyInfo instance of the indexed property, then use the SetProperty(Object, PropertyInfo, Object, ReflectionWays, Object) method for better performance.

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.

See Also