MethodBase.GetCurrentMethod 方法

返回表示当前正在执行的方法的 MethodBase 对象。

**命名空间:**System.Reflection
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public Shared Function GetCurrentMethod As MethodBase
用法
Dim returnValue As MethodBase

returnValue = MethodBase.GetCurrentMethod
public static MethodBase GetCurrentMethod ()
public:
static MethodBase^ GetCurrentMethod ()
public static MethodBase GetCurrentMethod ()
public static function GetCurrentMethod () : MethodBase

返回值

表示当前正在执行的方法的 MethodBase 对象。

示例

Imports System
Imports System.Reflection
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Messaging
Imports System.Security.Permissions

Namespace RemotingSamples
   <SecurityPermission(SecurityAction.Demand, Flags:=SecurityPermissionFlag.Infrastructure)> _
   Public Class HelloServer
      Inherits MarshalByRefObject
      
      Public Sub New()
         Console.WriteLine("HelloServer activated")
      End Sub 'New
      
      <OneWay(), SecurityPermission(SecurityAction.Demand, Flags:=SecurityPermissionFlag.Infrastructure)>  _
      Public Sub HelloToServer(name As String)
         Console.WriteLine("Hello.HelloToServer : {0}", name)
      End Sub 'HelloToServer
      
      <SecurityPermission(SecurityAction.Demand, Flags:=SecurityPermissionFlag.Infrastructure)> _
      Public Function HelloToServerAndWait(name As String) As String
         Console.WriteLine("Client invoked HelloToServerAndWait : " + name)
         Console.WriteLine("Client waiting for return? {0}", _
                   IIf(RemotingServices.IsOneWay(MethodBase.GetCurrentMethod()),"No","Yes"))
         Return "Hi there, " + name
      End Function 'HelloToServerAndWait
   End Class 'HelloServer
End Namespace 'RemotingSamples
using System;
using System.Reflection;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Messaging;
using System.Security.Permissions;

namespace RemotingSamples 
{
  [SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.Infrastructure)]
  public class HelloServer : MarshalByRefObject 
  {
    [SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.Infrastructure)]
    public HelloServer() 
    {
      Console.WriteLine("HelloServer activated");
    }

    [OneWay(), SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.Infrastructure)]
    public void HelloToServer(String name) 
    {
      Console.WriteLine("Hello.HelloToServer : {0}", name);
    }

    [SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.Infrastructure)]
    public String HelloToServerAndWait(String name)
    {
       Console.WriteLine("Client invoked HelloToServerAndWait : " + name);
       Console.WriteLine("Client waiting for return? {0}",
          RemotingServices.IsOneWay(MethodBase.GetCurrentMethod()) ? "No" : "Yes");
       return "Hi there, " + name;
    }
  }
}
#using <system.dll>
#using <system.runtime.remoting.dll>

using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Messaging;
using namespace System::Security::Permissions;

namespace RemotingSamples
{
   public ref class HelloServer: public MarshalByRefObject
   {
   public:
      HelloServer()
      {
         Console::WriteLine( "HelloServer activated" );
      }


      [OneWay]
      void HelloToServer( String^ name )
      {
         Console::WriteLine( "Hello::HelloToServer : {0}", name );
      }

      [SecurityPermissionAttribute(SecurityAction::Demand, Flags=SecurityPermissionFlag::Infrastructure)]   
      String^ HelloToServerAndWait( String^ name )
      {
         Console::WriteLine( "Client invoked HelloToServerAndWait : {0}", name );
         Console::WriteLine( "Client waiting for return? {0}", RemotingServices::IsOneWay( MethodBase::GetCurrentMethod() ) ? (String^)"No" : "Yes" );
         return "Hi there, {0}",name;
      }

   };

}

.NET Framework 安全性

平台

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 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

MethodBase 类
MethodBase 成员
System.Reflection 命名空间