InvokeMember Method

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Function InvokeMember ( _
    name As String, _
    invokeAttr As BindingFlags, _
    binder As Binder, _
    target As Object, _
    args As Object() _
) As Object
public Object InvokeMember(
    string name,
    BindingFlags invokeAttr,
    Binder binder,
    Object target,
    Object[] args
)
public:
Object^ InvokeMember(
    String^ name, 
    BindingFlags invokeAttr, 
    Binder^ binder, 
    Object^ target, 
    array<Object^>^ args
)
member InvokeMember : 
        name:string * 
        invokeAttr:BindingFlags * 
        binder:Binder * 
        target:Object * 
        args:Object[] -> Object 
public function InvokeMember(
    name : String, 
    invokeAttr : BindingFlags, 
    binder : Binder, 
    target : Object, 
    args : Object[]
) : Object

Parameters

  • name
    Type: System. . :: . .String
    The string containing the name of the constructor, method, property, or field member to invoke.
    -or-
    An empty string ("") to invoke the default member.
    -or-
    For IDispatch members, a string representing the DispID, for example "[DispID=3]".
  • invokeAttr
    Type: System.Reflection. . :: . .BindingFlags
    A bitmask comprised of one or more BindingFlags that specify how the search is conducted. The access can be one of the BindingFlags such as Public, NonPublic, Private, InvokeMethod, GetField, and so on. The type of lookup need not be specified. If the type of lookup is omitted, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static are used.
  • binder
    Type: System.Reflection. . :: . .Binder
    An object that defines a set of properties and enables binding, which can involve selection of an overloaded method, coercion of argument types, and invocation of a member through reflection.
    -or-
    A null reference (Nothing in Visual Basic), to use the DefaultBinder. Note that explicitly defining a Binder object may be required for successfully invoking method overloads with variable arguments.
  • args
    Type: array<System. . :: . .Object> [] () [] []
    An array containing the arguments to pass to the member to invoke.

Return Value

Type: System. . :: . .Object
An object representing the return value of the invoked member.

Remarks

Note

You cannot use InvokeMember to invoke a generic method.

The following BindingFlags filter flags can be used to define which members to include in the search:

  • Specify BindingFlags.Public to include public members in the search.

  • Specify BindingFlags.NonPublic to include non-public members (that is, private and protected members) in the search.

  • Specify BindingFlags.FlattenHierarchy to include static members up the hierarchy.

The following BindingFlags modifier flags can be used to change how the search works:

  • BindingFlags.IgnoreCase to ignore the case of name.

  • BindingFlags.DeclaredOnly to search only the members declared on the Type, not members that were simply inherited.

The following BindingFlags invocation flags can be used to denote what action to take with the member:

  • CreateInstance to invoke a constructor. name is ignored. Not valid with other invocation flags.

  • InvokeMethod to invoke a method, but not a constructor or a type initializer. Not valid with SetField or SetProperty. If InvokeMethod is specified by itself, BindingFlags.Public, BindingFlags.Instance, and BindingFlags.Static are automatically included.

  • GetField to get the value of a field. Not valid with SetField.

  • SetField to set the value of a field. Not valid with GetField.

  • GetProperty to get a property. Not valid with SetProperty.

  • SetProperty to set a property. Not valid with GetProperty.

See System.Reflection..::..BindingFlags for more information.

A method will be invoked if both of the following conditions are true:

  • The number of parameters in the method declaration equals the number of arguments in the args array (unless default arguments are defined on the member and BindingFlags.OptionalParamBinding is specified).

  • The type of each argument can be converted by the binder to the type of the parameter.

.NET Framework Security

See Also

Reference

Type Class

System Namespace