This documentation is archived and is not being maintained.
LogicalMethodInfo.Invoke Method
.NET Framework 1.1
Invokes the method represented by the current LogicalMethodInfo.
[Visual Basic] Public Function Invoke( _ ByVal target As Object, _ ByVal values() As Object _ ) As Object() [C#] public object[] Invoke( object target, object[] values ); [C++] public: Object* Invoke( Object* target, Object* values __gc[] ) __gc[]; [JScript] public function Invoke( target : Object, values : Object[] ) : Object[];
Parameters
- target
- The instance of the Object to invoke the method.
- values
- An argument list for the invoked method. This is an array of objects with the same number, order, and type as the parameters of the method. If the method does not require any parameters, the values parameter should be a null reference (Nothing in Visual Basic).
Return Value
An array of type Object representing the return value and out parameters of the invoked method.
Exceptions
| Exception Type | Condition |
|---|---|
| TargetException | The target parameter is a null reference (Nothing in Visual Basic). |
| ArgumentException | The number, type, and order of parameters in the values parameter do not match the signature of the invoked method. |
| MemberAccessException | The caller does not have permission to invoke the method. |
| TargetInvocationException | The invoked method throws an exception. |
Example
[Visual Basic] Imports System Imports System.Reflection Imports System.Web.Services.Protocols Imports Microsoft.VisualBasic Public Class MyService Public Function Add(xValue As Integer, yValue As Integer) As Integer Return xValue + yValue End Function 'Add End Class 'MyService Public Class LogicalMethodInfo_Constructor Public Shared Sub Main() Dim myType As Type = GetType(MyService) Dim myMethodInfo As MethodInfo = myType.GetMethod("Add") Dim myLogicalMethodInfo As New LogicalMethodInfo(myMethodInfo) Console.WriteLine(ControlChars.NewLine + "Printing properties of method : {0}" + _ ControlChars.NewLine, myLogicalMethodInfo.ToString()) Console.WriteLine(ControlChars.NewLine + "The declaring type of the method {0} is :" + _ ControlChars.NewLine, myLogicalMethodInfo.Name) Console.WriteLine(ControlChars.Tab + myLogicalMethodInfo.DeclaringType.ToString()) Console.WriteLine(ControlChars.NewLine + "The parameters of the method {0} are :" + _ ControlChars.NewLine, myLogicalMethodInfo.Name) Dim myParameters As ParameterInfo() = myLogicalMethodInfo.Parameters Dim i As Integer For i = 0 To myParameters.Length - 1 Console.WriteLine(ControlChars.Tab + myParameters(i).Name + " : " + _ myParameters(i).ParameterType.ToString()) Next i Console.WriteLine(ControlChars.NewLine + "The return type of the method {0} is :" + _ ControlChars.NewLine, myLogicalMethodInfo.Name) Console.WriteLine(ControlChars.Tab + myLogicalMethodInfo.ReturnType.ToString()) Dim service As New MyService() Console.WriteLine(ControlChars.NewLine + "Invoking the method {0}" + _ ControlChars.NewLine, myLogicalMethodInfo.Name) Console.WriteLine(ControlChars.Tab + "The sum of 10 and 10 is : {0}", _ myLogicalMethodInfo.Invoke(service, New Object() {10, 10})) End Sub 'Main End Class 'LogicalMethodInfo_Constructor [C#] using System; using System.Reflection; using System.Web.Services.Protocols; public class MyService { public int Add(int xValue, int yValue) { return (xValue + yValue); } } public class LogicalMethodInfo_Constructor { public static void Main() { Type myType = typeof(MyService); MethodInfo myMethodInfo = myType.GetMethod("Add"); LogicalMethodInfo myLogicalMethodInfo = new LogicalMethodInfo(myMethodInfo); Console.WriteLine("\nPrinting properties of method : {0}\n", myLogicalMethodInfo.ToString()); Console.WriteLine("\nThe declaring type of the method {0} is :\n", myLogicalMethodInfo.Name); Console.WriteLine("\t" + myLogicalMethodInfo.DeclaringType); Console.WriteLine("\nThe parameters of the method {0} are :\n", myLogicalMethodInfo.Name); ParameterInfo[] myParameters = myLogicalMethodInfo.Parameters; for(int i = 0; i < myParameters.Length; i++) { Console.WriteLine("\t" + myParameters[i].Name + " : " + myParameters[i].ParameterType); } Console.WriteLine("\nThe return type of the method {0} is :\n", myLogicalMethodInfo.Name); Console.WriteLine("\t" + myLogicalMethodInfo.ReturnType); MyService service = new MyService(); Console.WriteLine("\nInvoking the method {0}\n", myLogicalMethodInfo.Name); Console.WriteLine("\tThe sum of 10 and 10 is : {0}", myLogicalMethodInfo.Invoke(service, new object[] {10, 10})); } } [C++] #using <mscorlib.dll> #using <System.Web.Services.dll> using namespace System; using namespace System::Reflection; using namespace System::Web::Services::Protocols; public __gc class MyService { public: int Add(int xValue, int yValue) { return (xValue + yValue); } }; int main() { Type* myType = __typeof(MyService); MethodInfo* myMethodInfo = myType->GetMethod(S"Add"); LogicalMethodInfo* myLogicalMethodInfo = new LogicalMethodInfo(myMethodInfo); Console::WriteLine(S"\nPrinting properties of method : {0}\n", myLogicalMethodInfo); Console::WriteLine(S"\nThe declaring type of the method {0} is :\n", myLogicalMethodInfo->Name); Console::WriteLine(S"\t {0}", myLogicalMethodInfo->DeclaringType); Console::WriteLine(S"\nThe parameters of the method {0} are :\n", myLogicalMethodInfo->Name); ParameterInfo* myParameters[] = myLogicalMethodInfo->Parameters; for (int i = 0; i < myParameters->Length; i++) { Console::WriteLine(S"\t {0}",String::Concat(myParameters[i]->Name, S" : ", myParameters[i]->ParameterType)); } Console::WriteLine(S"\nThe return type of the method {0} is :\n", myLogicalMethodInfo->Name); Console::WriteLine(S"\t {0}", myLogicalMethodInfo->ReturnType); MyService* service = new MyService(); Console::WriteLine(S"\nInvoking the method {0}\n", myLogicalMethodInfo->Name); Object * values __gc[] = new Object * [2]; values[0] = __box(10); values[1] = __box(10); Console::WriteLine(S"\tThe sum of 10 and 10 is : {0}", myLogicalMethodInfo->Invoke(service,values)); }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
See Also
LogicalMethodInfo Class | LogicalMethodInfo Members | System.Web.Services.Protocols Namespace
Show: