EventInfo.EventHandlerType EventInfo.EventHandlerType EventInfo.EventHandlerType EventInfo.EventHandlerType Property

Definição

Obtém o objeto Type do delegado do manipulador de eventos subjacente associado a esse evento.Gets the Type object of the underlying event-handler delegate associated with this event.

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

Valor da propriedade

Um objeto Type somente leitura que representa o manipulador de eventos do delegado.A read-only Type object representing the delegate event handler.

Implementações

Exceções

O chamador não tem a permissão necessária.The caller does not have the required permission.

Exemplos

O exemplo a seguir usa EventHandlerType a propriedade para descobrir o tipo delegado de um evento e exibir seus tipos de parâmetro.The following example uses the EventHandlerType property to discover the delegate type of an event and to display its parameter types.

O exemplo define um delegado chamado MyDelegate e um evento chamado ev de tipo MyDelegate.The example defines a delegate named MyDelegate and an event named ev of type MyDelegate. O código no Main método descobre a assinatura do evento obtendo o tipo delegado do evento, obtendo o Invoke método do tipo delegado e, em seguida, recuperando e exibindo os parâmetros.The code in the Main method discovers the event signature by getting the delegate type of the event, getting the Invoke method of the delegate type, and then retrieving and displaying the parameters.

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

Aplica-se a

Veja também