Supports a specified member.
[Visual Basic] 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#] object InvokeMember( string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters ); [C++] Object* InvokeMember( String* name, BindingFlags invokeAttr, Binder* binder, Object* target, Object* args[], ParameterModifier* modifiers[], CultureInfo* culture, String* namedParameters[] ) = 0; [JScript] function InvokeMember( name : String, invokeAttr : BindingFlags, binder : Binder, target : Object, args : Object[], modifiers : ParameterModifier[], culture : CultureInfo, namedParameters : String[] ) : Object;
Exception Type | Condition |
---|---|
ArgumentException | If invokeAttr is CreateInstance and any one of the the other bit flags ae set. That is, if CreateInstance is set then none of the other flags should also be set. |
ArgumentException | If invokeAttr is not CreateInstance and name is null. |
ArgumentException | If invokeAttr isnot an invocation attribute from BindingFlags. |
ArgumentException | If invokeAttr specifies both get and set for a property or field. |
ArgumentException | If invokeAttr specifieds both field set and invoke method. args are provided for a field get. |
ArgumentException | If more than one argument is specified for a field set. |
MissingFieldException | The field or property cannot be found. |
MissingMethodException | The method cannot be found. |
SecurityException | There is an attempt to invoke a private member and the caller doesn not have the necessary ReflectionPermission NYI. |
The InvokeMember method invokes a 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.
A method will be invoked if the number of parameters in the method declaration equals the number of arguments in the specified argument list, and the type of each argument can be converted by the binder to the type of the parameter.
Note The array of parameter modifiers passed in to InvokeMember must contain a single parameter modifier. Only the first parameter modifier will be considered when determining which argument needs to be passed byref when exposed to COM.
The binder will find all of the matching methods. These methods are found based upon the type of binding requested (InvokeMethod, GetProperties, 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 is responsible for selecting the method to be invoked. The default binder selects the most specific match.
See the spec for possible remarks. It describes the 'Binding Process' and may indeed relate to InvokeMember.
The invokeAttr parameter maybe a constructor, method, property, or field. A suitable invocation attribute must be specified. Note that is possible to invoke the default member of a class by passing the empty string as the name of the member.
The binder parameter must be a bit flag from BindingFlags (InvokeMethod, CreateInstance, GetField, SetField, GetProperty, or SetProperty).
The target parameter is ignored if the member is static.
The args parameter is an array of objects that contains the number, order, and type of the parameters of the member to be invoked. If there are no parameters, this should be null.
The modifiers parameter has attributes associated with it in the metadata. Currently, a parameter can have the following attributes: pdIn, pdOut, pdRetval, pdOptional, and pdHasDefault. Respecitively, these represent [in], [out], [retval], [optional], and a parameter that has a default value. They are used by various interoperability services. See the metadata specs fo details such as this.
The culture parameter is an instance of CultureInfo used to govern the coercion of types. If this is null, the CultureInfo fo hte current thread is used. (Note: for example, this is necessary to convert a String that represents 1000 to a Double value, since 1000 is represented differently by different cultures.)
Access restrictions are ignored for fully trusted code. That is, private constructors, methods, fields, and properties can be accessed and invoked via Reflection whenever the code is fully trusted.
This managed C++ sample demonstrates how InvokeMember an be used to obtain the value of the Now property.
#import
using namespace Reflection;
#define NULL 0
void main()
{
Type *tDate = Type::GetType(L"System.DateTime");
Object result = tDate-> InvokeMember(L"Now", BindingFlags::GetProperty, NULL, NULL, new __managed Object[0];
Console::WriteLine(result.ToString());
}
/*
OUTPUT:
D:\CCOM>CORSDK\COMPILER\VC|cl.exe/EEi/c invokemember.cpp
Microsoft(R) 32-bit C/C++ Optiizing Compiler Vers. 13.00.8576 for 80x86 COM+
Copyright (C) Microsoft Corp 1992-1999. All rights reserved.
D:\CCOM>invokemember.exe
8/19/99 8:18:14 AM
*/
IReflect Interface | IReflect Members | System.Reflection Namespace | Object