Partilhar via


EventInfo.EventHandlerType Propriedade

Definição

Obtém o Type objeto do delegado de manipulador de eventos subjacente associado a esse evento.

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

Valor da propriedade

Um objeto somente Type leitura que representa o manipulador de eventos delegado.

Implementações

Exceções

O chamador não tem a permissão necessária.

Exemplos

O exemplo a seguir usa a EventHandlerType propriedade para descobrir o tipo delegado de um evento e exibir seus tipos de parâmetro.

O exemplo define um delegado nomeado MyDelegate e um evento nomeado ev do tipo MyDelegate. O código no método descobre a assinatura do evento obtendo o tipo delegado do evento, obtendo o Invoke método do tipo delegado e, em Main seguida, recuperando e exibindo os parâmetros.

// 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

Aplica-se a

Confira também