System.Reflection.EventInfo Class

public abstract class EventInfo : MemberInfo

Base Types

Object
  MemberInfo
    EventInfo

Assembly

mscorlib

Library

Reflection

Summary

Provides access to event metadata.

Description

Events are handled by delegates. An event listener supplies 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 of the source. When the event is raised, the event-handler delegate invokes the methods in its invocation list. The System.Reflection.EventInfo.GetAddMethod, System.Reflection.EventInfo.AddEventHandler(System.Object,System.Delegate) , System.Reflection.EventInfo.GetRemoveMethod, and System.Reflection.EventInfo.RemoveEventHandler(System.Object,System.Delegate) methods, and the delegate type of the event-handler associated with an event, are required to be marked in the metadata.

[Note: For information on delegates, see the Delegate class overview.]

[Note: For information on events, see Partitions I and II of the CLI specification.]

See Also

System.Reflection Namespace

Members

EventInfo Constructors

EventInfo Constructor

EventInfo Methods

EventInfo.AddEventHandler Method
EventInfo.GetAddMethod(bool) Method
EventInfo.GetAddMethod() Method
EventInfo.GetRaiseMethod(bool) Method
EventInfo.GetRaiseMethod() Method
EventInfo.GetRemoveMethod(bool) Method
EventInfo.GetRemoveMethod() Method
EventInfo.RemoveEventHandler Method

EventInfo Properties

EventInfo.Attributes Property
EventInfo.EventHandlerType Property


EventInfo Constructor

protected EventInfo();

Summary

Constructs a new instance of the EventInfo class.

See Also

System.Reflection.EventInfo Class, System.Reflection Namespace

EventInfo.AddEventHandler Method

public void AddEventHandler(object target, Delegate handler);

Summary

Adds the specified event handler delegate to the specified event source.

Parameters

target
An object that represents an event source.
handler
A Delegate instance to be added to target that references methods to be invoked when the event reflected by the current instance is raised by target.

Exceptions

Exception TypeCondition
ArgumentExceptionhandler is not the same type Type as the event handler delegate declared for the event reflected by the current instance.

TargetExceptionThe event reflected by the current instance is non-static, and obj is null or is of a type that does not implement the event reflected by the current instance.

Description

Each time the event reflected by the current instance is raised by target, the methods in the invocation list of handler are invoked.

See Also

System.Reflection.EventInfo Class, System.Reflection Namespace

EventInfo.GetAddMethod(bool) Method

public abstract MethodInfo GetAddMethod(bool nonPublic);

Summary

Returns the method used to add an event handler delegate to an event source for the event reflected by the current instance, specifying whether or not to return non-public methods.

Parameters

nonPublic
A Boolean value that specifies whether non-public methods can be returned by this method. Specify true to return non-public methods; otherwise, specify false .

Return Value

A MethodInfo instance that reflects the method used to add an event handler delegate to an event source for the event reflected by the current instance, if found; otherwise, returns null .

Exceptions

Exception TypeCondition
MethodAccessExceptionnonPublic is true , the method used to add an event handler delegate is non-public, and the caller does not have permission to reflect on non-public methods.

Description

[Note: The returned method is used to add an event-handler delegate to the invocation list of an event source. Typically, the method has the following signature format:

add_<EventName>(<EventHandlerType> handler)

]

[Behaviors: As described above.]

See Also

System.Reflection.EventInfo Class, System.Reflection Namespace

EventInfo.GetAddMethod() Method

public MethodInfo GetAddMethod();

Summary

Returns the public method used to add an event handler delegate to an event source for the event reflected by the current instance.

Return Value

A MethodInfo instance that reflects the public method used to add an event handler delegate to an event source for the event reflected by the current instance, if found; otherwise, returns null .

Description

This method is equivalent to System.Reflection.EventInfo.GetAddMethod(false ).

[Note: The returned method is used to add an event-handler delegate to the invocation list of an event source. Typically, the method has the following signature format:

add_<EventName>(<EventHandlerType> handler)

]

See Also

System.Reflection.EventInfo Class, System.Reflection Namespace

EventInfo.GetRaiseMethod(bool) Method

public abstract MethodInfo GetRaiseMethod(bool nonPublic);

Summary

Returns the method that is called when the event reflected by the current instance is raised, specifying whether the method to be returned is public or non-public.

Parameters

nonPublic
A Boolean value that specifies whether non-public methods can be returned by this method. Specify true to return non-public methods; otherwise, specify false .

Return Value

A MethodInfo instance that reflects the method that is called when the event reflected by the current instance is raised, if found; otherwise, returns null .

Exceptions

Exception TypeCondition
MethodAccessExceptionnonPublic is true , the method used to raise the event is non-public, and the caller does not have permission to reflect on non-public methods.

Description

[Behaviors: As described above.]

See Also

System.Reflection.EventInfo Class, System.Reflection Namespace

EventInfo.GetRaiseMethod() Method

public MethodInfo GetRaiseMethod();

Summary

Returns the public method that is called when the event reflected by the current instance is raised.

Return Value

A MethodInfo instance that reflects the public method that is called when the event reflected by the current instance is raised, if found; otherwise, returns null .

See Also

System.Reflection.EventInfo Class, System.Reflection Namespace

EventInfo.GetRemoveMethod(bool) Method

public abstract MethodInfo GetRemoveMethod(bool nonPublic);

Summary

Returns the method used to remove an event-handler delegate from the event reflected by the current instance, specifying whether or not to return non-public methods.

Parameters

nonPublic
A Boolean value that specifies whether non-public methods can be returned by this method. Specify true to return non-public methods; otherwise, specify false .

Return Value

A MethodInfo instance that reflects the method used to remove an event handler delegate from the event reflected by the current instance, if found; otherwise, returns null .

Exceptions

Exception TypeCondition
MethodAccessExceptionnonPublic is true , the method used to remove an event handler delegate is non-public, and the caller does not have permission to reflect on non-public methods.

Description

[Note: Typically, the method has the following signature format:

remove_<EventName>(<EventHandlerType> handler)

]

[Behaviors: As described above.]

See Also

System.Reflection.EventInfo Class, System.Reflection Namespace

EventInfo.GetRemoveMethod() Method

public MethodInfo GetRemoveMethod();

Summary

Returns the public method used to remove an event-handler delegate from the event reflected by the current instance.

Return Value

A MethodInfo instance that reflects the public method used to remove an event handler delegate from the event reflected by the current instance, if found; otherwise, returns null .

Description

This method is equivalent to System.Reflection.EventInfo.GetRemoveMethod(false ).

[Note: Typically, the method has the following signature format:

remove_<EventName>(<EventHandlerType> handler)

]

See Also

System.Reflection.EventInfo Class, System.Reflection Namespace

EventInfo.RemoveEventHandler Method

public void RemoveEventHandler(object target, Delegate handler);

Summary

Removes the specified event handler delegate from the specified event source.

Parameters

target
An object that represents an event source.
handler
A Delegate instance to be disassociated from the events reflected by the current instance that are raised by target.

Exceptions

Exception TypeCondition
ArgumentExceptionhandler is not the same type Type as the event handler delegate declared for the event reflected by the current instance.

Description

After this method is invoked, subsequent events reflected by the current instance that are raised by target will no longer cause handler to invoke its methods.

See Also

System.Reflection.EventInfo Class, System.Reflection Namespace

EventInfo.Attributes Property

public abstract EventAttributes Attributes { get; }

Summary

Gets the attributes of the event reflected by the current instance.

Property Value

A EventAttributes value that specifies the attributes in the metadata of the event reflected by the current instance.

See Also

System.Reflection.EventInfo Class, System.Reflection Namespace

EventInfo.EventHandlerType Property

public Type EventHandlerType { get; }

Summary

Gets the Type of the event-handler Delegate associated with the event reflected by the current instance.

Property Value

A Type that represents the type of the event-handler Delegate associated with the event reflected by the current instance. Returns null if the method used to add a delegate to the event is not public and is in a loaded assembly, and the caller does not have the required permission.

Description

This property is read-only.

See Also

System.Reflection.EventInfo Class, System.Reflection Namespace