TypeDelegator.InvokeMember Method (String, BindingFlags, Binder, Object, array<Object[], array<ParameterModifier[], CultureInfo, array<String[])

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Invokes the specified member. The method that is to be invoked must be accessible and provide the most specific match with the specified argument list, under the constraints of the specified binder and invocation attributes.

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

Syntax

'Declaration
Public Overrides Function InvokeMember ( _
    name As String, _
    invokeAttr As BindingFlags, _
    binder As Binder, _
    target As Object, _
    args As Object(), _
    modifiers As ParameterModifier(), _
    culture As CultureInfo, _
    namedParameters As String() _
) As Object
public override Object InvokeMember(
    string name,
    BindingFlags invokeAttr,
    Binder binder,
    Object target,
    Object[] args,
    ParameterModifier[] modifiers,
    CultureInfo culture,
    string[] namedParameters
)

Parameters

  • name
    Type: System.String
    The name of the member to invoke. This may be a constructor, method, property, or field. If an empty string ("") is passed, the default member is invoked.
  • invokeAttr
    Type: System.Reflection.BindingFlags
    The invocation attribute. This must be one of the following BindingFlags : InvokeMethod, CreateInstance, Static, GetField, SetField, GetProperty, or SetProperty. A suitable invocation attribute must be specified. If a static member is to be invoked, the Static flag must be set.
  • binder
    Type: System.Reflection.Binder
    An object that enables the binding, coercion of argument types, invocation of members, and retrieval of MemberInfo objects via reflection. If binder is nulla null reference (Nothing in Visual Basic), the default binder is used. See Binder.
  • target
    Type: System.Object
    The object on which to invoke the specified member.
  • args
    Type: array<System.Object[]
    An array of type Object that contains the number, order, and type of the parameters of the member to be invoked. If args contains an uninitialized Object, it is treated as empty, which, with the default binder, can be widened to 0, 0.0 or a string.
  • modifiers
    Type: array<System.Reflection.ParameterModifier[]
    An array of type ParameterModifer that is the same length as args, with elements that represent the attributes associated with the arguments of the member to be invoked. A parameter has attributes associated with it in the member's signature. For ByRef, use ParameterModifer.ByRef, and for none, use ParameterModifer.None. The default binder does exact matching on these. Attributes such as In and InOut are not used in binding, and can be viewed using ParameterInfo.
  • culture
    Type: System.Globalization.CultureInfo
    An instance of CultureInfo used to govern the coercion of types. This is necessary, for example, to convert a string that represents 1000 to a Double value, since 1000 is represented differently by different cultures. If culture is nulla null reference (Nothing in Visual Basic), the CultureInfo for the current thread's CultureInfo is used.
  • namedParameters
    Type: array<System.String[]
    An array of type String containing parameter names that match up, starting at element zero, with the args array. There must be no holes in the array. If args. Length is greater than namedParameters. Length, the remaining parameters are filled in order.

Return Value

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

Implements

IReflect.InvokeMember(String, BindingFlags, Binder, Object, array<Object[], array<ParameterModifier[], CultureInfo, array<String[])

Remarks

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

  • The number of parameters in the method declaration equals the number of arguments in the specified argument list (unless default arguments are defined on the member).

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

The binder will find all the matching methods. These methods are found based upon the type of binding requested (BindingFlags.MethodInvoke, BindingFlags.GetProperties, and so on). 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 Binder.BindToMethod method is responsible for selecting the method to be invoked. The default binder selects the most specific match.

NoteNote:

Access restrictions are ignored for fully trusted code. That is, private constructors, methods, fields, and properties can be accessed and invoked using reflection whenever the code is fully trusted.

Currently, InvokeMember performs the Microsoft .NET Framework reflection semantics for every type of object.

If the member specified by name is an array and the BindingFlags.GetField flag is set on invokeAttr, the args array specifies 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 Variant[]{0});

You can use InvokeMember to set one or more elements of a member array. All elements are set 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
    Variant[]{0,"Updated"});

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.