EventInfo Class
TOC
Collapse the table of content
Expand the table of content

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

NameDescription
System_CAPS_protmethodEventInfo()

Initializes a new instance of the EventInfo class.

NameDescription
System_CAPS_pubpropertyAddMethod

Gets the MethodInfo object for the AddEventHandler method of the event, including non-public methods.

System_CAPS_pubpropertyAttributes

Gets the attributes for this event.

System_CAPS_pubpropertyCustomAttributes

Gets a collection that contains this member's custom attributes.(Inherited from MemberInfo.)

System_CAPS_pubpropertyDeclaringType

Gets the class that declares this member.(Inherited from MemberInfo.)

System_CAPS_pubpropertyEventHandlerType

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

System_CAPS_pubpropertyIsMulticast

Gets a value indicating whether the event is multicast.

System_CAPS_pubpropertyIsSpecialName

Gets a value indicating whether the EventInfo has a name with a special meaning.

System_CAPS_pubpropertyMemberType

Gets a MemberTypes value indicating that this member is an event.(Overrides MemberInfo.MemberType.)

System_CAPS_pubpropertyMetadataToken

Gets a value that identifies a metadata element.(Inherited from MemberInfo.)

System_CAPS_pubpropertyModule

Gets the module in which the type that declares the member represented by the current MemberInfo is defined.(Inherited from MemberInfo.)

System_CAPS_pubpropertyName

Gets the name of the current member.(Inherited from MemberInfo.)

System_CAPS_pubpropertyRaiseMethod

Gets the method that is called when the event is raised, including non-public methods.

System_CAPS_pubpropertyReflectedType

Gets the class object that was used to obtain this instance of MemberInfo.(Inherited from MemberInfo.)

System_CAPS_pubpropertyRemoveMethod

Gets the MethodInfo object for removing a method of the event, including non-public methods.

NameDescription
System_CAPS_pubmethodAddEventHandler(Object, Delegate)

Adds an event handler to an event source.

System_CAPS_pubmethodEquals(Object)

Returns a value that indicates whether this instance is equal to a specified object.(Overrides MemberInfo.Equals(Object).)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetAddMethod()

Returns the method used to add an event handler delegate to the event source.

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

System_CAPS_pubmethodGetCustomAttributes(Boolean)

When overridden in a derived class, returns an array of all custom attributes applied to this member. (Inherited from MemberInfo.)

System_CAPS_pubmethodGetCustomAttributes(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.)

System_CAPS_pubmethodGetCustomAttributesData()

Returns a list of CustomAttributeData objects representing data about the attributes that have been applied to the target member.(Inherited from MemberInfo.)

System_CAPS_pubmethodGetHashCode()

Returns the hash code for this instance.(Overrides MemberInfo.GetHashCode().)

System_CAPS_pubmethodGetOtherMethods()

Returns the public methods that have been associated with an event in metadata using the .other directive.

System_CAPS_pubmethodGetOtherMethods(Boolean)

Returns the methods that have been associated with the event in metadata using the .other directive, specifying whether to include non-public methods.

System_CAPS_pubmethodGetRaiseMethod()

Returns the method that is called when the event is raised.

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

System_CAPS_pubmethodGetRemoveMethod()

Returns the method used to remove an event handler delegate from the event source.

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

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodIsDefined(Type, Boolean)

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

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodRemoveEventHandler(Object, Delegate)

Removes an event handler from an event source.

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_puboperatorSystem_CAPS_staticEquality(EventInfo, EventInfo)

Indicates whether two EventInfo objects are equal.

System_CAPS_puboperatorSystem_CAPS_staticInequality(EventInfo, EventInfo)

Indicates whether two EventInfo objects are not equal.

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethod_EventInfo.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Maps a set of names to a corresponding set of dispatch identifiers.

System_CAPS_pubinterfaceSystem_CAPS_privmethod_EventInfo.GetType()

Returns a T:System.Type object representing the EventInfo type.

System_CAPS_pubinterfaceSystem_CAPS_privmethod_EventInfo.GetTypeInfo(UInt32, UInt32, IntPtr)

Retrieves the type information for an object, which can then be used to get the type information for an interface.

System_CAPS_pubinterfaceSystem_CAPS_privmethod_EventInfo.GetTypeInfoCount(UInt32)

Retrieves the number of type information interfaces that an object provides (either 0 or 1).

System_CAPS_pubinterfaceSystem_CAPS_privmethod_EventInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Provides access to properties and methods exposed by an object.

System_CAPS_pubinterfaceSystem_CAPS_privmethod_MemberInfo.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Maps a set of names to a corresponding set of dispatch identifiers.(Inherited from MemberInfo.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod_MemberInfo.GetType()

Gets a Type object representing the MemberInfo class.(Inherited from MemberInfo.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod_MemberInfo.GetTypeInfo(UInt32, UInt32, IntPtr)

Retrieves the type information for an object, which can then be used to get the type information for an interface.(Inherited from MemberInfo.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod_MemberInfo.GetTypeInfoCount(UInt32)

Retrieves the number of type information interfaces that an object provides (either 0 or 1).(Inherited from MemberInfo.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod_MemberInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Provides access to properties and methods exposed by an object.(Inherited from MemberInfo.)

NameDescription
System_CAPS_pubmethodGetCustomAttribute(Type)

Overloaded. Retrieves a custom attribute of a specified type that is applied to a specified member.(Defined by CustomAttributeExtensions.)

System_CAPS_pubmethodGetCustomAttribute(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.)

System_CAPS_pubmethodGetCustomAttribute<T>()

Overloaded. Retrieves a custom attribute of a specified type that is applied to a specified member.(Defined by CustomAttributeExtensions.)

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

System_CAPS_pubmethodGetCustomAttributes()

Overloaded. Retrieves a collection of custom attributes that are applied to a specified member.(Defined by CustomAttributeExtensions.)

System_CAPS_pubmethodGetCustomAttributes(Type)

Overloaded. Retrieves a collection of custom attributes of a specified type that are applied to a specified member.(Defined by CustomAttributeExtensions.)

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

System_CAPS_pubmethodIsDefined(Type)

Overloaded. Indicates whether custom attributes of a specified type are applied to a specified member.(Defined by CustomAttributeExtensions.)

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

System_CAPS_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);
        }
    }
}

SecurityAction.InheritanceDemand

for full trust for inheritors. This class cannot be inherited by partially trusted code.

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1

This type is thread safe.

Return to top
Show:
© 2016 Microsoft