public abstract class EventInfo : MemberInfo
Object
MemberInfo
EventInfo
mscorlib
Reflection
Provides access to event metadata.
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.]
System.Reflection Namespace
EventInfo Constructors
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
protected EventInfo();
Constructs a new instance of the EventInfo class.
System.Reflection.EventInfo Class, System.Reflection Namespace
public void AddEventHandler(object target, Delegate handler);
Adds the specified event handler delegate to the specified event source.
- 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.
Exception Type Condition ArgumentException handler is not the same type Type as the event handler delegate declared for the event reflected by the current instance.
TargetException The 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.
Each time the event reflected by the current instance is raised by target, the methods in the invocation list of handler are invoked.
System.Reflection.EventInfo Class, System.Reflection Namespace
public abstract MethodInfo GetAddMethod(bool nonPublic);
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.
- nonPublic
- A Boolean value that specifies whether non-public methods can be returned by this method. Specify
true
to return non-public methods; otherwise, specifyfalse
.
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, returnsnull
.
Exception Type Condition MethodAccessException nonPublic 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.
[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.]
System.Reflection.EventInfo Class, System.Reflection Namespace
public MethodInfo GetAddMethod();
Returns the public method used to add an event handler delegate to an event source for the event reflected by the current instance.
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, returnsnull
.
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)
]
System.Reflection.EventInfo Class, System.Reflection Namespace
public abstract MethodInfo GetRaiseMethod(bool nonPublic);
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.
- nonPublic
- A Boolean value that specifies whether non-public methods can be returned by this method. Specify
true
to return non-public methods; otherwise, specifyfalse
.
A MethodInfo instance that reflects the method that is called when the event reflected by the current instance is raised, if found; otherwise, returnsnull
.
Exception Type Condition MethodAccessException nonPublic 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.
[Behaviors: As described above.]
System.Reflection.EventInfo Class, System.Reflection Namespace
public MethodInfo GetRaiseMethod();
Returns the public method that is called when the event reflected by the current instance is raised.
A MethodInfo instance that reflects the public method that is called when the event reflected by the current instance is raised, if found; otherwise, returnsnull
.
System.Reflection.EventInfo Class, System.Reflection Namespace
public abstract MethodInfo GetRemoveMethod(bool nonPublic);
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.
- nonPublic
- A Boolean value that specifies whether non-public methods can be returned by this method. Specify
true
to return non-public methods; otherwise, specifyfalse
.
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, returnsnull
.
Exception Type Condition MethodAccessException nonPublic 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.
[Note: Typically, the method has the following signature format:
remove_<EventName>(<EventHandlerType> handler)
]
[Behaviors: As described above.]
System.Reflection.EventInfo Class, System.Reflection Namespace
public MethodInfo GetRemoveMethod();
Returns the public method used to remove an event-handler delegate from the event reflected by the current instance.
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, returnsnull
.
This method is equivalent to System.Reflection.EventInfo.GetRemoveMethod(false
).[Note: Typically, the method has the following signature format:
remove_<EventName>(<EventHandlerType> handler)
]
System.Reflection.EventInfo Class, System.Reflection Namespace
public void RemoveEventHandler(object target, Delegate handler);
Removes the specified event handler delegate from the specified event source.
- 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.
Exception Type Condition ArgumentException handler is not the same type Type as the event handler delegate declared for the event reflected by the current instance.
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.
System.Reflection.EventInfo Class, System.Reflection Namespace
public abstract EventAttributes Attributes { get; }
Gets the attributes of the event reflected by the current instance.
A EventAttributes value that specifies the attributes in the metadata of the event reflected by the current instance.
System.Reflection.EventInfo Class, System.Reflection Namespace
public Type EventHandlerType { get; }
Gets the Type of the event-handler Delegate associated with the event reflected by the current instance.
A Type that represents the type of the event-handler Delegate associated with the event reflected by the current instance. Returnsnull
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.
This property is read-only.
System.Reflection.EventInfo Class, System.Reflection Namespace