PostSharpAPI ReferencePost­Sharp.​Aspects.​AdvicesOn­Event­Add­Handler­Advice
Open sandboxFocus

OnEventAddHandlerAdvice Class

Custom attribute that, when applied on a method of an aspect class, specifies that this method is an advice having the same semantics as OnAddHandler(EventInterceptionArgs).

Inheritance
OnEventAddHandlerAdvice
Namespace: PostSharp.Aspects.Advices
Assembly: PostSharp.dll
Syntax
[RequiresEventInterceptionAdviceAnalysis]
[RequiresDebuggerEnhancement]
public sealed class OnEventAddHandlerAdvice : GroupingAdvice
Remarks

The method to which this custom attribute is applied must be public and must have the same signature as OnAddHandler(EventInterceptionArgs). However, it can be static.

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.


If an aspect defines many advices (among OnEventAddHandlerAdvice , OnEventRemoveHandlerAdvice and OnEventInvokeHandlerAdvice ) that are meant to be applied to the same events with consistent ordering, these advices should be grouped together (see Master property).

note

Standalone advices or group masters should also be annotated by a custom attribute derived from Pointcut .

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

Constructors

Name Description
OnEventAddHandlerAdvice()

See Also