LogicalMethodInfo.Invoke Method (Object, Object())

 

Invokes the method represented by the current LogicalMethodInfo.

Namespace:   System.Web.Services.Protocols
Assembly:  System.Web.Services (in System.Web.Services.dll)

<PermissionSetAttribute(SecurityAction.LinkDemand, Name := "FullTrust")>
Public Function Invoke (
	target As Object,
	values As Object()
) As Object()

Parameters

target
Type: System.Object

The instance of the Object to invoke the method.

values
Type: System.Object()

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 null.

Return Value

Type: System.Object()

An array of type Object representing the return value and out parameters of the invoked method.

Exception Condition
TargetException

The target parameter is null.

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.

Imports System
Imports System.Reflection
Imports System.Security.Permissions
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

Class LogicalMethodInfo_Constructor

<PermissionSetAttribute(SecurityAction.Demand, Name := "FullTrust")>  _
   Shared Sub Run()
      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 'Run

   Shared Sub Main()
      Run()
   End Sub 'Main
End Class 'LogicalMethodInfo_Constructor

.NET Framework
Available since 1.1
Return to top
Show: