EventInfo.EventHandlerType 속성

정의

이 이벤트와 연결된 내부 이벤트 처리기 대리자의 Type 개체를 가져옵니다.

public:
 virtual property Type ^ EventHandlerType { Type ^ get(); };
public:
 property Type ^ EventHandlerType { Type ^ get(); };
public virtual Type EventHandlerType { get; }
public virtual Type? EventHandlerType { get; }
public Type EventHandlerType { get; }
member this.EventHandlerType : Type
Public Overridable ReadOnly Property EventHandlerType As Type
Public ReadOnly Property EventHandlerType As Type

속성 값

Type

대리자 이벤트 처리기를 나타내는 읽기 전용 Type 개체입니다.

구현

예외

호출자에게 필요한 권한이 없는 경우

예제

다음 예제에서는 속성을 사용 하 여 EventHandlerType 이벤트의 대리자 형식을 검색 하 고 해당 매개 변수 형식을 표시 합니다.

이 예제에서는 명명 MyDelegate 된 대리자와 형식MyDelegate의 이벤트를 ev 정의합니다. 메서드의 Main 코드는 이벤트의 대리자 형식을 가져오고 대리자 형식의 메서드를 Invoke 가져온 다음 매개 변수를 검색하고 표시하여 이벤트 서명을 검색합니다.

// The following example uses instances of classes in
// the System::Reflection namespace to discover an event argument type.
using namespace System;
using namespace System::Reflection;

public delegate void MyDelegate( int i );
public ref class MainClass
{
public:
   event MyDelegate^ ev;
};

int main()
{
   Type^ delegateType = MainClass::typeid->GetEvent( "ev" )->EventHandlerType;
   MethodInfo^ invoke = delegateType->GetMethod( "Invoke" );
   array<ParameterInfo^>^pars = invoke->GetParameters();
   System::Collections::IEnumerator^ myEnum = pars->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      ParameterInfo^ p = safe_cast<ParameterInfo^>(myEnum->Current);
      Console::WriteLine( p->ParameterType );
   }
}
// The example displays the following output:
//       System.Int32
// The following example uses instances of classes in
// the System.Reflection namespace to discover an event argument type.
using System;
using System.Reflection;

public delegate void MyDelegate(int i);
public class MainClass
{
    public event MyDelegate ev;

    public static void Main()
    {
        Type delegateType = typeof(MainClass).GetEvent("ev").EventHandlerType;
        MethodInfo invoke = delegateType.GetMethod("Invoke");
        ParameterInfo[] pars = invoke.GetParameters();
        foreach (ParameterInfo p in pars)
        {
            Console.WriteLine(p.ParameterType);
        }
    }
}
// The example displays the following output:
//       System.Int32
Imports System.Reflection

Public Delegate Sub MyDelegate(ByVal i As Integer)

Public Class MainClass
    Public Event ev As MyDelegate

    Public Shared Sub Main()
        Dim delegateType As Type = GetType(MainClass).GetEvent("ev").EventHandlerType
        Dim invoke As MethodInfo = delegateType.GetMethod("Invoke")
        Dim pars As ParameterInfo() = invoke.GetParameters()
        For Each p As ParameterInfo In pars
            Console.WriteLine(p.ParameterType)
        Next 
    End Sub 
End Class 
' The example displays the following output:
'     System.Int32

적용 대상

추가 정보