Export (0) Print
Expand All

EventInfo Class

Discovers the attributes of an event and provides access to event metadata.

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

[SerializableAttribute]
[ClassInterfaceAttribute(ClassInterfaceType.None)]
[ComVisibleAttribute(true)]
[PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
public abstract class EventInfo : MemberInfo, 
	_EventInfo

The EventInfo type exposes the following members.

  NameDescription
Protected methodSupported by the XNA FrameworkEventInfoInitializes a new instance of the EventInfo class.
Top

  NameDescription
Public propertySupported in .NET for Windows Store appsAddMethodGets the MethodInfo object for the AddEventHandler method of the event, including non-public methods.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsAttributesGets the attributes for this event.
Public propertySupported in .NET for Windows Store appsCustomAttributesGets a collection that contains this member's custom attributes. (Inherited from MemberInfo.)
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsDeclaringTypeGets the class that declares this member. (Inherited from MemberInfo.)
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsEventHandlerTypeGets the Type object of the underlying event-handler delegate associated with this event.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibraryIsMulticastGets a value indicating whether the event is multicast.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIsSpecialNameGets a value indicating whether the EventInfo has a name with a special meaning.
Public propertySupported by the XNA FrameworkMemberTypeGets a MemberTypes value indicating that this member is an event. (Overrides MemberInfo.MemberType.)
Public propertyMetadataTokenGets a value that identifies a metadata element. (Inherited from MemberInfo.)
Public propertySupported in .NET for Windows Store appsModuleGets the module in which the type that declares the member represented by the current MemberInfo is defined. (Inherited from MemberInfo.)
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsNameGets the name of the current member. (Inherited from MemberInfo.)
Public propertySupported in .NET for Windows Store appsRaiseMethodGets the method that is called when the event is raised, including non-public methods.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibraryReflectedTypeGets the class object that was used to obtain this instance of MemberInfo. (Inherited from MemberInfo.)
Public propertySupported in .NET for Windows Store appsRemoveMethodGets the MethodInfo object for removing a method of the event, including non-public methods.
Top

  NameDescription
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsAddEventHandlerAdds an event handler to an event source.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryEqualsReturns a value that indicates whether this instance is equal to a specified object. (Overrides MemberInfo.Equals(Object).)

In XNA Framework 3.0, this member is inherited from Object.Equals(Object).


In Portable Class Library Portable Class Library, this member is inherited from Object.Equals(Object).
Protected methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetAddMethod()Returns the method used to add an event handler delegate to the event source.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetAddMethod(Boolean)When overridden in a derived class, retrieves the MethodInfo object for the AddEventHandler method of the event, specifying whether to return non-public methods.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetCustomAttributes(Boolean)When overridden in a derived class, returns an array of all custom attributes applied to this member. (Inherited from MemberInfo.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetCustomAttributes(Type, Boolean)When overridden in a derived class, returns an array of custom attributes applied to this member and identified by Type. (Inherited from MemberInfo.)
Public methodGetCustomAttributesDataReturns a list of CustomAttributeData objects representing data about the attributes that have been applied to the target member. (Inherited from MemberInfo.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetHashCodeReturns the hash code for this instance. (Overrides MemberInfo.GetHashCode().)

In XNA Framework 3.0, this member is inherited from Object.GetHashCode().


In Portable Class Library Portable Class Library, this member is inherited from Object.GetHashCode().
Public methodGetOtherMethods()Returns the public methods that have been associated with an event in metadata using the .other directive.
Public methodGetOtherMethods(Boolean)Returns the methods that have been associated with the event in metadata using the .other directive, specifying whether to include non-public methods.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetRaiseMethod()Returns the method that is called when the event is raised.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetRaiseMethod(Boolean)When overridden in a derived class, returns the method that is called when the event is raised, specifying whether to return non-public methods.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetRemoveMethod()Returns the method used to remove an event handler delegate from the event source.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetRemoveMethod(Boolean)When overridden in a derived class, retrieves the MethodInfo object for removing a method of the event, specifying whether to return non-public methods.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryIsDefinedWhen overridden in a derived class, indicates whether one or more attributes of the specified type or of its derived types is applied to this member. (Inherited from MemberInfo.)
Protected methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsRemoveEventHandlerRemoves an event handler from an event source.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public operatorStatic memberEqualityIndicates whether two EventInfo objects are equal.
Public operatorStatic memberInequalityIndicates whether two EventInfo objects are not equal.
Top

  NameDescription
Public Extension MethodSupported in .NET for Windows Store appsGetCustomAttribute(Type)Overloaded. Retrieves a custom attribute of a specified type that is applied to a specified member. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsGetCustomAttribute(Type, Boolean)Overloaded. Retrieves a custom attribute of a specified type that is applied to a specified member, and optionally inspects the ancestors of that member. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsGetCustomAttribute<T>()Overloaded. Retrieves a custom attribute of a specified type that is applied to a specified member. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsGetCustomAttribute<T>(Boolean)Overloaded. Retrieves a custom attribute of a specified type that is applied to a specified member, and optionally inspects the ancestors of that member. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsGetCustomAttributes()Overloaded. Retrieves a collection of custom attributes that are applied to a specified member. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsGetCustomAttributes(Boolean)Overloaded. Retrieves a collection of custom attributes that are applied to a specified member, and optionally inspects the ancestors of that member. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsGetCustomAttributes(Type)Overloaded. Retrieves a collection of custom attributes of a specified type that are applied to a specified member. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsGetCustomAttributes(Type, Boolean)Overloaded. Retrieves a collection of custom attributes of a specified type that are applied to a specified member, and optionally inspects the ancestors of that member. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsGetCustomAttributes<T>()Overloaded. Retrieves a collection of custom attributes of a specified type that are applied to a specified member. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsGetCustomAttributes<T>(Boolean)Overloaded. Retrieves a collection of custom attributes of a specified type that are applied to a specified member, and optionally inspects the ancestors of that member. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsIsDefined(Type)Overloaded. Indicates whether custom attributes of a specified type are applied to a specified member. (Defined by CustomAttributeExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsIsDefined(Type, Boolean)Overloaded. Indicates whether custom attributes of a specified type are applied to a specified member, and, optionally, applied to its ancestors. (Defined by CustomAttributeExtensions.)
Top

  NameDescription
Explicit interface implemetationPrivate method_EventInfo.GetIDsOfNamesMaps a set of names to a corresponding set of dispatch identifiers.
Explicit interface implemetationPrivate method_EventInfo.GetTypeReturns a T:System.Type object representing the EventInfo type.
Explicit interface implemetationPrivate method_EventInfo.GetTypeInfoRetrieves the type information for an object, which can then be used to get the type information for an interface.
Explicit interface implemetationPrivate method_EventInfo.GetTypeInfoCountRetrieves the number of type information interfaces that an object provides (either 0 or 1).
Explicit interface implemetationPrivate method_EventInfo.InvokeProvides access to properties and methods exposed by an object.
Explicit interface implemetationPrivate method_MemberInfo.GetIDsOfNamesMaps a set of names to a corresponding set of dispatch identifiers. (Inherited from MemberInfo.)
Explicit interface implemetationPrivate method_MemberInfo.GetTypeGets a Type object representing the MemberInfo class. (Inherited from MemberInfo.)
Explicit interface implemetationPrivate method_MemberInfo.GetTypeInfoRetrieves the type information for an object, which can then be used to get the type information for an interface. (Inherited from MemberInfo.)
Explicit interface implemetationPrivate method_MemberInfo.GetTypeInfoCountRetrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from MemberInfo.)
Explicit interface implemetationPrivate method_MemberInfo.InvokeProvides access to properties and methods exposed by an object. (Inherited from MemberInfo.)
Top

Use the EventInfo class to inspect events and to hook up event handlers, as shown in the example code for the AddEventHandler method.

NoteNote

EventInfo is not intended to be used to raise events. An object raises events as dictated by its internal state.

Events are used with delegates. An event listener instantiates an event-handler delegate that is invoked whenever the event is raised by an event source. In order to connect to the event source, the event listener adds this delegate to the invocation list on the source. When the event is raised, the invoke method of the event-handler delegate is called. Both multicast and single-cast event notifications are supported. The Add and Remove methods, as well as the event-handler delegate class associated with an event, must be marked in the metadata.

Delegates are object-oriented function pointers. In C or C++, a function pointer is a reference to a method. In contrast to the C or C++ function pointer, a delegate contains two references: a reference to a method and a reference to an object that supports the method. Delegates can invoke a method without knowing the class type that declares or inherits the method. Delegates need only know the return type and parameter list of the method.

The event model works equally well for single-cast and multicast delegates. When the delegate's invoke method is called, only a single object will have a method called on it. A multicast modifier can be applied to a delegate declaration, which allows multiple methods to be called when the invoke method of the delegate is called.

Calling ICustomAttributeProvider.GetCustomAttributes on EventInfo when the inherit parameter of GetCustomAttributes is true does not walk the type hierarchy. Use System.Attribute to inherit custom attributes.

Notes to Inheritors

When you inherit from EventInfo, you must override the following members: GetAddMethod, GetRemoveMethod, and GetRaiseMethod.

The following code gets an EventInfo object for the Click event of the Button class.

using System;
using System.Reflection;
using System.Security;

class MyEventExample
{
    public static void Main()
    {  
        try
        {

            // Creates a bitmask based on BindingFlags.
            BindingFlags myBindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
            Type myTypeBindingFlags = typeof(System.Windows.Forms.Button);
            EventInfo myEventBindingFlags = myTypeBindingFlags.GetEvent("Click", myBindingFlags);
            if(myEventBindingFlags != null)
            {
                Console.WriteLine("Looking for the Click event in the Button class with the specified BindingFlags.");
                Console.WriteLine(myEventBindingFlags.ToString());
            }
            else
                Console.WriteLine("The Click event is not available with the Button class.");
        }
        catch(SecurityException e)
        {
            Console.WriteLine("An exception occurred.");
            Console.WriteLine("Message :"+e.Message);
        }
        catch(ArgumentNullException e)
        {
            Console.WriteLine("An exception occurred.");
            Console.WriteLine("Message :"+e.Message);
        }
        catch(Exception e)
        {
            Console.WriteLine("The following exception was raised : {0}",e.Message);
        }
    }
}

.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 Store apps

Supported in: Windows 8

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

This type is thread safe.

Show:
© 2014 Microsoft