Aspect that, when applied on an event, intercepts invocations of its semantics Add (OnAddHandler(EventInterceptionArgs)),
Remove (OnRemoveHandler(EventInterceptionArgs)) and Invoke (OnInvokeHandler(EventInterceptionArgs)).
Inheritance
Implements
Namespace: PostSharp.Aspects
Assembly: PostSharp.dll
Syntax
[HasInheritedAttribute]
[MulticastAttributeUsage(MulticastTargets.Event, AllowMultiple = true, PersistMetaData = false, TargetMemberAttributes = MulticastAttributes.NonAbstract)]
[AttributeUsage(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Event|AttributeTargets.Interface, AllowMultiple = true)]
[AspectConfigurationAttributeType(typeof(EventInterceptionAspectConfigurationAttribute))]
[Serializer(null)]
public abstract class EventInterceptionAspect : EventLevelAspect, IEventLevelAspectBuildSemantics, IAspectBuildSemantics, IValidableAnnotation, IEventInterceptionAspect, IEventLevelAspect, IAspectRemarks
<p>
Applying an aspect of type <xref href="PostSharp.Aspects.EventInterceptionAspect" data-throw-if-not-resolved="false"></xref> to an event results in the <code>add</code> and <code>remove</code>
methods of the event to be replaced by a call to <xref href="PostSharp.Aspects.EventInterceptionAspect.OnAddHandler(PostSharp.Aspects.EventInterceptionArgs)" data-throw-if-not-resolved="false"></xref> and <xref href="PostSharp.Aspects.EventInterceptionAspect.OnRemoveHandler(PostSharp.Aspects.EventInterceptionArgs)" data-throw-if-not-resolved="false"></xref>, respectively.
The original accessor body is moved into new methods, which the aspect code can call by invoking <xref href="PostSharp.Aspects.EventInterceptionArgs.ProceedAddHandler" data-throw-if-not-resolved="false"></xref>
or <xref href="PostSharp.Aspects.EventInterceptionArgs.ProceedRemoveHandler" data-throw-if-not-resolved="false"></xref>.
</p>
<p>
The method <xref href="PostSharp.Aspects.EventInterceptionAspect.OnInvokeHandler(PostSharp.Aspects.EventInterceptionArgs)" data-throw-if-not-resolved="false"></xref>, if defined, is called instead when the event is raised, <i>once for every handler</i> that has been added
to the list. When you define <xref href="PostSharp.Aspects.EventInterceptionAspect.OnInvokeHandler(PostSharp.Aspects.EventInterceptionArgs)" data-throw-if-not-resolved="false"></xref> method, PostSharp will use a broker object to control access to the event; this broker
object will be the unique subscriber of the event, and maintains its own list of subscribers.
</p>
<p>
<div class="NOTE"><h5>note</h5><p>
The aspect works only when caller code access the event through its <code>add</code>/<code>remove</code> semantics. It does not work when the caller
code bypasses the event semantics and accesses directly its implementation (the underlying field of the event, typically). The C# compiler
is known to bypass the semantics when the event is accessed directly from the class declaring it (it accesses directly the private field
whenever it can).
</p></div>
</p>
<p>
note
All classes implementing IAspect should typically be marked as serializable using the SerializableAttribute or PSerializableAttribute custom attribute . Fields that are only used at runtime (and unknown at compile-time) should be carefully marked with the NonSerializedAttribute or PNonSerializedAttribute custom attribute. When PostSharp is used on a platform that does not support aspect serialization (such as .NET Compact Framework, Silverlight, or Windows Phone), or when another aspect serializer is used, it is not necessary to mark the aspect class as serializable. For more information, see Understanding Aspect Serialization .
Constructors
| Name | Description |
|---|---|
| EventInterceptionAspect() |
Methods
| Name | Description |
|---|---|
| CreateAspectConfiguration() | Method invoked at build time to create a concrete AspectConfiguration instance specifically for the current Aspect type. |
| OnAddHandler(EventInterceptionArgs) | Method invoked instead of the |
| OnInvokeHandler(EventInterceptionArgs) | Method invoked when the event to which the current aspect is applied is fired, for each delegate of this event, and instead of invoking this delegate. |
| OnRemoveHandler(EventInterceptionArgs) | Method invoked instead of the |