EventInfo.EventHandlerType Propiedad

Definición

Obtiene el objeto Type del controlador de eventos subyacente asociado a este 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 de propiedad

Objeto Type de sólo lectura que representa el controlador de eventos delegado.

Implementaciones

Excepciones

El llamador no dispone del permiso requerido.

Ejemplos

En el ejemplo siguiente se usa la EventHandlerType propiedad para detectar el tipo delegado de un evento y mostrar sus tipos de parámetros.

En el ejemplo se define un delegado denominado MyDelegate y un evento denominado ev de tipo MyDelegate. El código del Main método detecta la firma de evento obteniendo el tipo de delegado del evento, obteniendo el Invoke método del tipo delegado y recuperando y mostrando los parámetros.

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

Se aplica a

Consulte también