Freigeben über


LogicalMethodInfo.Invoke-Methode

Ruft die durch die aktuelle LogicalMethodInfo dargestellte Methode auf.

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

Syntax

'Declaration
Public Function Invoke ( _
    target As Object, _
    values As Object() _
) As Object()
'Usage
Dim instance As LogicalMethodInfo
Dim target As Object
Dim values As Object()
Dim returnValue As Object()

returnValue = instance.Invoke(target, values)
public Object[] Invoke (
    Object target,
    Object[] values
)
public:
array<Object^>^ Invoke (
    Object^ target, 
    array<Object^>^ values
)
public Object[] Invoke (
    Object target, 
    Object[] values
)
public function Invoke (
    target : Object, 
    values : Object[]
) : Object[]

Parameter

  • target
    Die Instanz des Object zum Aufrufen der Methode.
  • values
    Eine Argumentliste für die aufgerufene Methode. Dies ist ein Array von Objekten mit derselben Nummer, derselben Reihenfolge und demselben Typ wie die Parameter der Methode. Wenn für die Methode keine Parameter erforderlich sind, sollte der values-Parameter NULL (Nothing in Visual Basic) sein.

Rückgabewert

Ein Array vom Typ Object, das den Rückgabewert und die Out-Parameter der aufgerufenen Methode darstellt.

Ausnahmen

Ausnahmetyp Bedingung

TargetException

Der target-Parameter ist NULL (Nothing in Visual Basic).

ArgumentException

Anzahl, Typ und Reihenfolge der Parameter im values-Parameter stimmen nicht mit der Signatur der aufgerufenen Methode überein.

MemberAccessException

Der Aufrufer verfügt nicht über die Berechtigung zum Aufrufen der Methode.

TargetInvocationException

Die aufgerufene Methode löst eine Ausnahme aus.

Beispiel

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
using System;
using System.Reflection;
using System.Security.Permissions;
using System.Web.Services.Protocols;

public class MyService 
{
   public int Add(int xValue, int yValue)
   {
      return (xValue + yValue);
   }
}

class LogicalMethodInfo_Constructor
{
   [PermissionSetAttribute(SecurityAction.Demand, Name="FullTrust")]
   static void Run()
   {
      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}));

   }
   
   static void Main()
   {
      Run();
   }  
}
#using <System.Web.Services.dll>

using namespace System;
using namespace System::Reflection;
using namespace System::Web::Services::Protocols;

public ref class MyService
{
public:
   int Add( int xValue, int yValue )
   {
      return (xValue + yValue);
   }

};

int main()
{
   Type^ myType = MyService::typeid;
   MethodInfo^ myMethodInfo = myType->GetMethod( "Add" );
   LogicalMethodInfo^ myLogicalMethodInfo = gcnew LogicalMethodInfo( myMethodInfo );
   Console::WriteLine( "\nPrinting properties of method : {0}\n", myLogicalMethodInfo );
   Console::WriteLine( "\nThe declaring type of the method {0} is :\n", myLogicalMethodInfo->Name );
   Console::WriteLine( "\t {0}", myLogicalMethodInfo->DeclaringType );
   Console::WriteLine( "\nThe parameters of the method {0} are :\n", myLogicalMethodInfo->Name );
   array<ParameterInfo^>^myParameters = myLogicalMethodInfo->Parameters;
   for ( int i = 0; i < myParameters->Length; i++ )
   {
      Console::WriteLine( "\t {0}", String::Concat( myParameters[ i ]->Name, " : ", myParameters[ i ]->ParameterType ) );
   }
   Console::WriteLine( "\nThe return type of the method {0} is :\n", myLogicalMethodInfo->Name );
   Console::WriteLine( "\t {0}", myLogicalMethodInfo->ReturnType );
   MyService^ service = gcnew MyService;
   Console::WriteLine( "\nInvoking the method {0}\n", myLogicalMethodInfo->Name );
   array<Object^>^values = gcnew array<Object^>(2);
   values[ 0 ] = 10;
   values[ 1 ] = 10;
   Console::WriteLine( "\tThe sum of 10 and 10 is : {0}", myLogicalMethodInfo->Invoke( service, values ) );
}

Plattformen

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

LogicalMethodInfo-Klasse
LogicalMethodInfo-Member
System.Web.Services.Protocols-Namespace