Open sandboxFocus
  • TOC

Post­Sharp Documentation

Introduction

Deployment and Configuration

Adding Aspects to Code

Logging

Contracts

INotify­Property­Changed

Weak Event

XAML

Parent/Child, Visitor and Disposable

Undo/Redo

Caching

Multithreading

Developing Custom Aspects

Validating Architecture

Testing and Debugging

Miscellaneous

API Reference

Post­Sharp

Post­Sharp.​Aspects

Advice­Args

Arguments

Aspect3

Aspect­Description­Attribute2

Aspect­Info

Aspect­Instance2

Aspect­Specification

Aspect­Utilities

Assembly­Level­Aspect4

Async­Call­Id

Composition­Aspect5

Constructor­Depth

Custom­Attribute­Introduction­Aspect

Event­Interception­Args2

Event­Interception­Aspect5

Event­Level­Aspect4

Field­Level­Aspect4

Flow­Behavior

IAspect

IAspect­Build­Semantics

IAspect­Instance

IAspect­Provider

IAspect­Repository­Service

IAssembly­Level­Aspect

IAssembly­Level­Aspect­Build­Semantics

IAsync­Method­Binding

IAsync­Method­Interception­Aspect

IClone­Aware­Aspect

IComposition­Aspect

ICustom­Attribute­Introduction­Aspect

IEvent­Binding

IEvent­Interception­Aspect

IEvent­Level­Aspect

IEvent­Level­Aspect­Build­Semantics

IField­Level­Aspect

IField­Level­Aspect­Build­Semantics

IInstance­Scoped­Aspect

ILocation­Binding

ILocation­Binding<T>

ILocation­Binding­Action<TPayload>

ILocation­Interception­Args

ILocation­Interception­Args<T>

ILocation­Interception­Args­Action<TPayload>

ILocation­Interception­Aspect

ILocation­Level­Aspect

ILocation­Level­Aspect­Build­Semantics

ILocation­Validation­Aspect

ILocation­Validation­Aspect<T>

IManaged­Resource­Introduction­Aspect

IMethod­Binding

IMethod­Interception­Aspect

IMethod­Level­Aspect

IMethod­Level­Aspect­Build­Semantics

Instance­Level­Aspect5

IOn­Exception­Aspect

IOn­Instance­Location­Initialized­Aspect

IOn­Method­Boundary­Aspect

IOn­State­Machine­Boundary­Aspect

IType­Level­Aspect

IType­Level­Aspect­Build­Semantics

Lines­Of­Code­Avoided­Attribute2

Location­Binding­Extensions

Location­Initialization­Args3

Location­Interception­Args3

Location­Interception­Aspect5

Location­Level­Aspect4

Location­Validation­Context

Managed­Resource­Introduction­Aspect

Method­Binding­Invoke­Awaitable

Method­Binding­Invoke­Awaiter

Method­Execution­Args2

Method­Implementation­Aspect5

Method­Interception­Args2

Method­Interception­Aspect5

Method­Interception­Proceed­Awaitable

Method­Interception­Proceed­Awaiter

Method­Level­Aspect4

Module­Initializer­Attribute2

Null­Task­Sentinel

On­Exception­Aspect5

On­Method­Boundary­Aspect5

Semantically­Advised­Method­Kinds

Type­Identity

Type­Level­Aspect4

Unsupported­Target­Action

Post­Sharp.​Aspects.​Advices

Post­Sharp.​Aspects.​Configuration

Post­Sharp.​Aspects.​Dependencies

Post­Sharp.​Aspects.​Internals

Post­Sharp.​Aspects.​Serialization

Post­Sharp.​Collections

Post­Sharp.​Constraints

Post­Sharp.​Extensibility

Post­Sharp.​Extensibility.​Build­Time­Logging

Post­Sharp.​Patterns

Post­Sharp.​Patterns.​Caching

Post­Sharp.​Patterns.​Caching.​Backends

Post­Sharp.​Patterns.​Caching.​Backends.​Azure

Post­Sharp.​Patterns.​Caching.​Backends.​Redis

Post­Sharp.​Patterns.​Caching.​Dependencies

Post­Sharp.​Patterns.​Caching.​Formatters

Post­Sharp.​Patterns.​Caching.​Implementation

Post­Sharp.​Patterns.​Caching.​Locking

Post­Sharp.​Patterns.​Caching.​Serializers

Post­Sharp.​Patterns.​Caching.​Value­Adapters

Post­Sharp.​Patterns.​Collections

Post­Sharp.​Patterns.​Collections.​Advices

Post­Sharp.​Patterns.​Contracts

Post­Sharp.​Patterns.​Diagnostics

Post­Sharp.​Patterns.​Diagnostics.​Adapters.​Asp­Net­Core

Post­Sharp.​Patterns.​Diagnostics.​Adapters.​Asp­Net­Framework

Post­Sharp.​Patterns.​Diagnostics.​Adapters.​Diagnostic­Source

Post­Sharp.​Patterns.​Diagnostics.​Adapters.​Http­Client

Post­Sharp.​Patterns.​Diagnostics.​Audit

Post­Sharp.​Patterns.​Diagnostics.​Backends

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Application­Insights

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Audit

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Common­Logging

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Console

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Event­Source

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Log4Net

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Microsoft

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Multiplexer

Post­Sharp.​Patterns.​Diagnostics.​Backends.​NLog

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Null

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Serilog

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Trace

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Trace­Source

Post­Sharp.​Patterns.​Diagnostics.​Contexts

Post­Sharp.​Patterns.​Diagnostics.​Correlation

Post­Sharp.​Patterns.​Diagnostics.​Custom

Post­Sharp.​Patterns.​Diagnostics.​Custom.​Messages

Post­Sharp.​Patterns.​Diagnostics.​Formatters

Post­Sharp.​Patterns.​Diagnostics.​Record­Builders

Post­Sharp.​Patterns.​Diagnostics.​Threading­Instrumentation

Post­Sharp.​Patterns.​Diagnostics.​Transactions

Post­Sharp.​Patterns.​Diagnostics.​Transactions.​Model

Post­Sharp.​Patterns.​Dynamic­Advising

Post­Sharp.​Patterns.​Formatters

Post­Sharp.​Patterns.​Model

Post­Sharp.​Patterns.​Model.​Controls

Post­Sharp.​Patterns.​Model.​Type­Adapters

Post­Sharp.​Patterns.​Recording

Post­Sharp.​Patterns.​Recording.​Operations

Post­Sharp.​Patterns.​Threading

Post­Sharp.​Patterns.​Threading.​Models

Post­Sharp.​Patterns.​Utilities

Post­Sharp.​Patterns.​Xaml

Post­Sharp.​Reflection

Post­Sharp.​Reflection.​Method­Body

Post­Sharp.​Serialization

  • Article

Class EventInterceptionAspect

Aspect that, when applied on an event, intercepts invocations of its semantics Add (OnAddHandler(EventInterceptionArgs)), Remove (OnRemoveHandler(EventInterceptionArgs)) and Invoke (OnInvokeHandler(EventInterceptionArgs)).

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, IAspect
Remarks

Applying an aspect of type EventInterceptionAspect to an event results in the add and remove methods of the event to be replaced by a call to OnAddHandler(EventInterceptionArgs) and OnRemoveHandler(EventInterceptionArgs), respectively. The original accessor body is moved into new methods, which the aspect code can call by invoking ProceedAddHandler() or ProceedRemoveHandler().

The method OnInvokeHandler(EventInterceptionArgs), if defined, is called instead when the event is raised, once for every handler that has been added to the list. When you define OnInvokeHandler(EventInterceptionArgs) 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.

note

The aspect works only when caller code access the event through its add/remove 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).

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 .

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 Add semantic of the event to which the current aspect is applied, i.e. when a new delegate is added to this event.

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 Remove semantic of the event to which the current aspect is applied, i.e. when a delegate is removed from this event.

See Also

  • Navigation

See also