NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Type.InvokeMember (String, BindingFlags, Binder, Object, Object[], CultureInfo)

Invokes the specified member, using the specified binding constraints and matching the specified argument list and culture.

[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, _
   ByVal culture As CultureInfo _
) As Object
[C#]
public object InvokeMember(
   string name,
   BindingFlags invokeAttr,
   Binder binder,
   object target,
   object[] args,
   CultureInfo culture
);
[C++]
public: Object* InvokeMember(
   String* name,
   BindingFlags invokeAttr,
   Binder* binder,
   Object* target,
   Object* args[],
   CultureInfo* culture
);
[JScript]
public function InvokeMember(
   name : String,
   invokeAttr : BindingFlags,
   binder : Binder,
   target : Object,
   args : Object[],
   culture : CultureInfo
) : Object;

Parameters

name
The String containing the name of the constructor, method, property, or field member to invoke.

-or-

An empty string ("") to invoke the default member.

invokeAttr
A bit mask comprised of one or more BindingFlags that specify how the search is conducted.

-or-

zero, to conduct a case-sensitive search for public methods.

binder
A Binder object that defines a set of properties and enables binding, which may involve selection of an overloaded method, coercion of argument types, and invocation of a member through reflection.

-or-

a null reference (in Visual Basic Nothing), to use the DefaultBinder.

target
The Object on which to invoke the specified member.
args
An array containing the arguments to pass to the member to invoke.
culture
The CultureInfo object representing the globalization locale to use, which may be necessary for locale-specific conversions, such as converting a numeric String to a Double.

-or-

a null reference (Nothing) to use the current thread's CultureInfo.

Return Value

An Object representing the return value of the invoked member.

Exceptions

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.

Remarks

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.

Other BindingFlags values can include InvokeMethod, CreateInstance, GetField, SetField, GetProperty, or SetProperty. CreateInstance cannot be combined with InvokeMethod, GetField, SetField, GetProperty, or SetProperty.

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}, null);

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"}, null);

See Also

Type Class | Type Members | System Namespace | Type.InvokeMember Overload List | String | Binder | DefaultBinder | BindingFlags | ParameterModifier