Invokes the specified member, using the specified binding constraints and matching the specified argument list.
[Visual Basic] Overloads Public Function InvokeMember( _ ByVal name As String, _ ByVal invokeAttr As BindingFlags, _ ByVal binder As Binder, _ ByVal target As Object, _ ByVal args() As Object _ ) As Object [C#] public object InvokeMember( string name, BindingFlags invokeAttr, Binder binder, object target, object[] args ); [C++] public: Object* InvokeMember( String* name, BindingFlags invokeAttr, Binder* binder, Object* target, Object* args[] ); [JScript] public function InvokeMember( name : String, invokeAttr : BindingFlags, binder : Binder, target : Object, args : Object[] ) : Object;
-or-
An empty string ("") to invoke the default member.
-or-
zero, to conduct a case-sensitive search for public methods.
-or-
a null reference (in Visual Basic Nothing), to use the DefaultBinder.
An Object representing the return value of the invoked member.
Exception Type | Condition |
---|---|
ArgumentNullException | invokeAttr contains CreateInstance and typeName is a null reference (Nothing). |
ArgumentException | args is multidimensional.
-or- invokeAttr is not a valid BindingFlags attribute. -or- invokeAttr contains CreateInstance combined with InvokeMethod, GetField, SetField, GetProperty, or SetProperty. -or- invokeAttr contains both GetField and SetField. -or- invokeAttr contains both GetProperty and SetProperty. -or- invokeAttr contains InvokeMethod combined with SetField or SetProperty. -or- invokeAttr contains SetField and args has more than one element. |
AccessException | The specified member is a class initializer. |
MissingFieldException | The field or property cannot be found. |
MissingMethodException | The method cannot be found. |
SecurityException | The specified member is non-public and the caller does not have ReflectionPermission to reflect non-public members outside the current assembly. |
TargetException | The specified member cannot be invoked on target. |
The following BindingFlags filter flags can be used to define which members should be included in the search:
The following BindingFlags modifier flags can be used to change how the search works:
The following BindingFlags invocation flags can be used to denote what action to take with the member:
See BindingFlags for more information.
A method will be invoked if:
The binder will find all of the matching methods. These methods are found based upon the type of binding requested (BindingFlags values InvokeMethod, GetProperty, etc.). The set of methods is filtered by the name, number of arguments, and a set of search modifiers defined in the binder.
After the method is selected, it will be invoked. Accessibility is checked at that point. The search may control which set of methods are searched based upon the accessibility attribute associated with the method. The BindToMethod method of the Binder class is responsible for selecting the method to be invoked. The default binder selects the most specific match.
Access restrictions are ignored for fully trusted code; that is, private constructors, methods, fields, and properties can be accessed and invoked through System.Reflection whenever the code is fully trusted.
If the member specified by name is an array and invokeAttr contains the GetField flag, the args array must specify the elements whose values are to be returned. For example, the following call through Type object t returns the value of the first element of the string array MyArray, which is a member of the calling object:
String ret = (String) t.InvokeMember ("MyArray", BindingFlags.GetField, null, this, new Object[]{0});
InvokeMember can also set one or more elements of a member array to the same value. The args array must be formatted as follows: "{index1, index2, ..., value}".
For example, to set the first member of MyArray from the previous example, the syntax is as follows:
t.InvokeMember ("MyArray", BindingFlags.SetField, null, this, new Object[]{0,"Updated"});
Type Class | Type Members | System Namespace | Type.InvokeMember Overload List | String | Binder | DefaultBinder | BindingFlags | ParameterModifier