When implemented by a derived class, invokes the specified member, using the specified binding constraints and matching the specified argument list, modifiers and culture.
[Visual Basic] Overloads MustOverride Public Function InvokeMember( _ ByVal name As String, _ ByVal invokeAttr As BindingFlags, _ ByVal binder As Binder, _ ByVal target As Object, _ ByVal args() As Object, _ ByVal modifiers() As ParameterModifier, _ ByVal culture As CultureInfo, _ ByVal namedParameters() As String _ ) As Object [C#] public abstract object InvokeMember( string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters ); [C++] public: virtual Object* InvokeMember( String* name, BindingFlags invokeAttr, Binder* binder, Object* target, Object* args[], ParameterModifier* modifiers[], CultureInfo* culture, String* namedParameters[] ) = 0; [JScript] public abstract function InvokeMember( name : String, invokeAttr : BindingFlags, binder : Binder, target : Object, args : Object[], modifiers : ParameterModifier[], culture : CultureInfo, namedParameters : String[] ) : 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.
-or-
a null reference (Nothing) to use the current thread's CultureInfo.
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- modifiers is multidimensional. -or- args and modifiers do not have the same length. -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. |
Abstract. This method must be implemented by a derived class.
The args array and the modifiers array have the same length. A parameter specified in the args array can have the following attributes, which are specified in the modifiers array: pdIn, pdOut, pdLcid, pdRetval, pdOptional, and pdHasDefault, which represent [in], [out], [lcid], [retval], [optional], and a value specifying whether the parameter has a default value. A parameter's associated attributes are stored in the metadata and are used for interoperability.
Each parameter in the namedParameters array gets the value in the corresponding element in the args array. If the length of args is greater than the length of namedParameters, the remaining argument values are passed in order.
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