Export (0) Print
Expand All

EventInfo.EventHandlerType Property

Gets the Type object of the underlying event-handler delegate associated with this event.

[Visual Basic]
Public ReadOnly Property EventHandlerType As Type
[C#]
public Type EventHandlerType {get;}
[C++]
public: __property Type* get_EventHandlerType();
[JScript]
public function get EventHandlerType() : Type;

Property Value

A read-only Type object representing the delegate event handler.

Exceptions

Exception Type Condition
SecurityException The caller does not have the required permission.

Example

[Visual Basic] 
' The following example uses instances of classes in 
' the System.Reflection namespace to discover an event argument type.
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

Public Class MainClass
    Delegate Sub MyDelegate(ByVal i As Integer)
    Public Event ev As MyDelegate
    Public Sub Fire(ByVal i As Integer)
        AddHandler ev, AddressOf Me.Fire
    End Sub 'Fire

    Public Shared Sub Main()
        Dim deleg As Type = GetType(MainClass).GetEvent("ev").EventHandlerType
        Dim invoke As MethodInfo = deleg.GetMethod("Invoke")
        Dim pars As ParameterInfo() = invoke.GetParameters()
        Dim p As ParameterInfo
        For Each p In pars
            Console.WriteLine(p.ParameterType)
        Next p
    End Sub 'Main
End Class 'MainClass

[C#] 
// 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 void Fire(int i) 
    {
        ev += new MyDelegate(this.Fire);
    }

    public static void Main() 
    {
        Type deleg = typeof(MainClass).GetEvent("ev").EventHandlerType;
        MethodInfo invoke = deleg.GetMethod("Invoke");
        ParameterInfo[] pars = invoke.GetParameters();
        foreach (ParameterInfo p in pars) 
        {
            Console.WriteLine(p.ParameterType);
        }
    }
}

[C++] 
// The following example uses instances of classes in
// the System::Reflection namespace to discover an event argument type.
#using <mscorlib.dll>

using namespace System;
using namespace System::Reflection;

public __delegate void MyDelegate(int  i);

public __gc class MainClass {
public:
   __event MyDelegate*  ev;
public:
   void Fire(int i) {
      ev += new MyDelegate(this, &MainClass::Fire);
   }
};

int main() {
   Type*  deleg = __typeof(MainClass)->GetEvent(S"ev")->EventHandlerType;
   MethodInfo*  invoke = deleg->GetMethod(S"Invoke");
   ParameterInfo*  pars[] = invoke->GetParameters();
   System::Collections::IEnumerator* myEnum = pars->GetEnumerator();
   while (myEnum->MoveNext()) {
      ParameterInfo* p = __try_cast<ParameterInfo*>(myEnum->Current);
      Console::WriteLine(p->ParameterType);
   }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

.NET Framework Security: 

See Also

EventInfo Class | EventInfo Members | System.Reflection Namespace | Type | Delegate | EventHandler

Show:
© 2015 Microsoft