MethodAccessorInvoke(Object, Object) Method

Invokes the method. The return value of void methods is always . For static methods the instance parameter is omitted (can be ).

Definition

Namespace: KGySoft.Reflection
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.0.0
C#
public Object? Invoke(
	Object? instance,
	params Object?[]? parameters
)

Parameters

instance  Object
The instance that the method belongs to. Can be for static methods.
parameters  Object
The parameters to be used for invoking the method. If the method has ref/out parameters the corresponding array elements are assigned back with the results.

Return Value

Object
The return value of the method, or for void methods.

Remarks

Invoking the method for the first time is slower than the System.Reflection.MethodBase.Invoke method but further calls are much faster.

If the method has ref/ parameters pass a preallocated array to parameters. The parameters passed by reference will be assigned back to the corresponding array elements.

  Notes to Callers

If the method is a non-readonly instance method of a value type or has ref/ or pointer parameters/return value, then the .NET Standard 2.0 version of this method defaults to use regular reflection to preserve possible mutations and be able to assign the parameter values back to the parameters array. To experience the best performance try to target .NET Standard 2.1 or any .NET Framework or .NET Core/.NET platforms instead.

Exceptions

ArgumentNullExceptionThis MethodAccessor represents an instance method and instance is .
-or-
This MethodAccessor represents a method with parameters and parameters is .
ArgumentExceptionThe type of instance or one of the parameters is invalid.
-or-
parameters has too few elements.
InvalidOperationExceptionThis MethodAccessor represents an open generic method or a method of an open generic type.
NotSupportedExceptionOn .NET Framework the code is executed in a partially trusted domain with insufficient permissions.
PlatformNotSupportedExceptionYou use the .NET Standard 2.0 build of KGySoft.CoreLibraries and this MethodAccessor represents a ref-returning method.

See Also