ReflectorInvokeMethod(Type, String, Boolean, Type, ReflectionWays, Object) Method

Invokes a static method of a Type represented by the specified methodName.

Definition

Namespace: KGySoft.Reflection
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.0.0
C#
public static Object? InvokeMethod(
	Type type,
	string methodName,
	bool ignoreCase,
	Type[]? genericParameters,
	ReflectionWays way,
	params Object?[]? parameters
)

Parameters

type  Type
The Type the static method belongs to.
methodName  String
The name of the method to be invoked.
ignoreCase  Boolean
to ignore case; to regard case.
genericParameters  Type
Type parameters if methodName refers to a generic method definition. Otherwise, this parameter is ignored.
way  ReflectionWays
The preferred reflection way. TypeDescriptor way is not applicable for invoking methods.
parameters  Object
The parameters to be used for invoking the method.

Return Value

Object
The return value of the method.

Remarks

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 genericParameters and parameters match.

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

If you are not sure whether a method with the specified methodName exists, then you can use the TryInvokeMethod methods instead.

If way is Auto, then the DynamicDelegate way will be used.

See Also