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

Tries to invoke 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 bool TryInvokeMethod(
	Type type,
	string methodName,
	bool ignoreCase,
	Type[]? genericParameters,
	ReflectionWays way,
	out Object?? result,
	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.
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 genericParameters and parameters match.

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

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

See Also