ReflectorTrySetIndexedMember(Object, Object, 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,
	params Object?[] indexParameters
)

Parameters

instance  Object
An instance to be set.
value  Object
The value to set.
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.

For setting an indexed property this method uses the DynamicDelegate reflection way.

  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