ReflectorInvokeMethod(Object, MethodInfo, Object) Method

Invokes a method represented by the specified MethodInfo.

Definition

Namespace: KGySoft.Reflection
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 8.1.0
C#
public static Object? InvokeMethod(
	Object? instance,
	MethodInfo method,
	params Object?[]? parameters
)

Parameters

instance  Object
An instance whose method is about to be invoked. This parameter is ignored for static methods.
method  MethodInfo
The method to be invoked.
parameters  Object
The parameters to be used for invoking the method.

Return Value

Object
The return value of the method.

Remarks

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 is an instance member of 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.

  Note

To invoke the method explicitly by dynamically created delegates use the MethodAccessor class.

See Also