Mono Class Library: System.Reflection.MethodBase Overview | Members

System.Reflection.MethodBase.Invoke Method

Invokes the method or constructor reflected by the current instance on the specified object and using the specified arguments.

[System.Diagnostics.DebuggerStepThrough]
public object Invoke (object obj, object[] parameters)

Parameters

obj
An instance of a type that contains the constructor or method reflected by the current instance. If the member is static, obj is ignored. For non-static methods, obj is an instance of a class that inherits or declares the method.
parameters
An array objects that match the number, order and type of the parameters for the constructor or method reflected by the current instance. If the member reflected by the current instance takes no parameters, specify either an array with zero elements or null .
Note: Any object in this array that is not explicitly initialized with a value will contain the default value for that object type. For reference-type elements, this value is null. For value-type elements, this value is 0, 0.0, or false, depending on the specific element type. If the method or constructor reflected by the current instance is static , this parameter is ignored.
parameters
Documentation for this section has not yet been entered.

Returns

A object that contains the return value of the invoked method, or a re-initialized object if a constructor was invoked.

Permissions

TypeReason
System.Security.Permissions.ReflectionPermissionRequires permission to invoke non-public members of loaded assemblies. See System.Security.Permissions.ReflectionPermissionFlag.MemberAccess.

Exceptions

TypeReason
ArgumentExceptionThe types of the elements of parameters do not match the types of the parameters accepted by the constructor or method reflected by the current instance, under the constraints of the default binder.
System.Reflection.TargetExceptionThe constructor or method reflected by the current instance is non-static and obj is null, or is of a type that does not implement the member reflected by the current instance.
System.Reflection.TargetInvocationExceptionThe constructor or method reflected by the current instance threw an exception.
System.Reflection.TargetParameterCountExceptionparameters.Length does not equal the number of parameters required by the contract of the member reflected by the current instance.
MemberAccessExceptionThe caller does not have permission to execute the method or constructor.
InvalidOperationExceptionThe type that declares the method is an open generic type. That is, Type.ContainsGenericParameters returns true for the declaring type.

Remarks

This version of MethodBase.Invoke(object, Object[]) is equivalent to MethodBase.Invoke(object, Object[])(obj, (BindingFlags)0, null, parameters, null).

Optional parameters cannot be omitted in calls to MethodBase.Invoke(object, Object[]) .

Requirements

Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0