Export (0) Print
Expand All

Type.GetEvents Method

Returns all the public events that are declared or inherited by the current Type.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

abstract GetEvents : unit -> EventInfo[] 
override GetEvents : unit -> EventInfo[] 

Return Value

Type: System.Reflection.EventInfo[]
An array of EventInfo objects representing all the public events which are declared or inherited by the current Type.
-or-
An empty array of type EventInfo, if the current Type does not have public events.

Implements

_Type.GetEvents()

An event is considered public to reflection if it has at least one method or accessor that is public. Otherwise the event is considered private, and you must use BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static (in Visual Basic, combine the values using Or) to get it.

The GetEvents method does not return events in a particular order, such as alphabetical or declaration order. Your code must not depend on the order in which events are returned, because that order varies.

This method can be overridden by a derived class.

The following table shows what members of a base class are returned by the Get methods when reflecting on a type.

Member Type

Static

Non-Static

Constructor

No

No

Field

No

Yes. A field is always hide-by-name-and-signature.

Event

Not applicable

The common type system rule is that the inheritance is the same as that of the methods that implement the property. Reflection treats properties as hide-by-name-and-signature. See note 2 below.

Method

No

Yes. A method (both virtual and non-virtual) can be hide-by-name or hide-by-name-and-signature.

Nested Type

No

No

Property

Not applicable

The common type system rule is that the inheritance is the same as that of the methods that implement the property. Reflection treats properties as hide-by-name-and-signature. See note 2 below.

  1. Hide-by-name-and-signature considers all of the parts of the signature, including custom modifiers, return types, parameter types, sentinels, and unmanaged calling conventions. This is a binary comparison.

  2. For reflection, properties and events are hide-by-name-and-signature. If you have a property with both a get and a set accessor in the base class, but the derived class has only a get accessor, the derived class property hides the base class property, and you will not be able to access the setter on the base class.

  3. Custom attributes are not part of the common type system.

If the current Type represents a constructed generic type, this method returns the EventInfo objects with the type parameters replaced by the appropriate type arguments.

If the current Type represents a type parameter in the definition of a generic type or generic method, this method searches the events of the class constraint.

The following example obtains an array of EventInfo objects, gets all the events for a Button class, and displays the event names. To compile the Visual Basic example, use the following command line:

vbc type_getevents1.vb /r:System.Windows.Forms.dll /r:System.dll

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft