ReflectorTryInvokeMethod(Object, String, Boolean, Object, Object) Method

Tries to invoke an instance method of an object represented by the specified methodName.

Definition

Namespace: KGySoft.Reflection
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 8.1.0
C#
public static bool TryInvokeMethod(
	Object instance,
	string methodName,
	bool ignoreCase,
	out Object?? result,
	params Object?[]? parameters
)

Parameters

instance  Object
An instance whose method is about to be invoked.
methodName  String
The name of the method to be invoked.
ignoreCase  Boolean
to ignore case; to regard case.
result  Object
When this method returns with result, then this parameter contains the return value of the method.
parameters  Object
The parameters to be used for invoking the method.

Return Value

Boolean
, if the method could be invoked; , if a matching method could not be found.

Remarks

  Note

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

methodName can refer public and non-public methods. To avoid ambiguity this method gets all of the methods of the same name and chooses the first one for which the provided parameters match.

If you already have a MethodInfo instance use the InvokeMethod(Object, MethodInfo, Type, ReflectionWays, Object) method for better performance.

For invoking the method this method uses the DynamicDelegate reflection way, except when the .NET Standard 2.0 version of the KGySoft.CoreLibraries assembly is referenced and the method belongs to a value type (struct) or has ref/out parameters, in which case the SystemReflection 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