PostSharp 2023.0 / / Post­Sharp Documentation / API Reference / Post­Sharp.​Aspects Namespace / Event­Interception­Aspect Class / Event­Interception­Aspect Methods / Event­Interception­Aspect.​On­Add­Handler Method

EventInterceptionAspect.OnAddHandler Method

Method invoked instead of the Add semantic of the event to which the current aspect is applied, i.e. when a new delegate is added to this event.

Namespace:  PostSharp.Aspects
Assembly:  PostSharp (in PostSharp.dll) Version: 2023.0.3.0 (2023.0.3.0)
public virtual void OnAddHandler(
	EventInterceptionArgs args


Type: PostSharp.Aspects.EventInterceptionArgs
Handler arguments.



This advice does not intercept the initializer of a field-like event. If you want to intercept the adding of all handlers, do not use event initializers and instead add the initial handler in the constructor.

Note Note
Because of the way how the C# compiler implements field-like events (i.e. events where you don't implement the Add and Remove semantics manually), the Invoke Event Handler semantic ( OnInvokeHandler(EventInterceptionArgs) or equivalent) shall not be invoked for delegates that have been added from inside the class that declares this event.
See Also