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.
public static Object? InvokeMethod(
Object instance,
string methodName,
bool ignoreCase,
ReflectionWays way,
params Object?[]? parameters
)
Public Shared Function InvokeMethod (
instance As Object,
methodName As String,
ignoreCase As Boolean,
way As ReflectionWays,
ParamArray parameters As Object()
) As Object
public:
static Object^ InvokeMethod(
Object^ instance,
String^ methodName,
bool ignoreCase,
ReflectionWays way,
... array<Object^>^ parameters
)
static member InvokeMethod :
instance : Object *
methodName : string *
ignoreCase : bool *
way : ReflectionWays *
parameters : Object[] -> Object
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.
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, 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.