EventInfo.EventHandlerType Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém o Type objeto do delegado handler de eventos subjacente associado a este evento.
public:
virtual property Type ^ EventHandlerType { Type ^ get(); };
public:
property Type ^ EventHandlerType { Type ^ 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 de Propriedade
Um objeto de apenas Type leitura que representa o gestor de eventos de delegado.
Implementações
Exceções
O interlocutor não tem a permissão necessária.
Exemplos
O exemplo seguinte utiliza a EventHandlerType propriedade para descobrir o tipo de delegado de um evento e para mostrar os seus tipos de parâmetros.
O exemplo define um delegado nomeado MyDelegate e um evento nomeado ev do tipo MyDelegate. O código no Main método descobre a assinatura do evento ao obter o tipo delegado do evento, obter o Invoke método do tipo delegado e depois recuperar e mostrar 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