PostSharpAPI ReferencePost­Sharp.​Patterns.​ModelWeak­Event­Attribute
Open sandboxFocus

WeakEventAttribute Class

Aspect that, when applied to an event, prevents the target event from holding a strong reference to event handlers. Therefore, the aspect prevents the event to prevent clients to be garbage collected.

Namespace: PostSharp.Patterns.Model
Assembly: PostSharp.Patterns.Model.dll
Syntax
[LinesOfCodeAvoided(6)]
[Serializer]
public sealed class WeakEventAttribute : EventInterceptionAspect, IEventLevelAspectBuildSemantics, IAspectBuildSemantics, IValidableAnnotation, IEventInterceptionAspect, IEventLevelAspect, IInstanceScopedAspect, IAspect
Remarks

Event clients do not need to keep a strong reference to the delegates passed to a weak event. The WeakEventAttribute implementation will keep delegate instances alive as long as the event source (i.e. whatever object the Target property points to) is alive, but no longer.

Constructors

Name Description
WeakEventAttribute()
WeakEventAttribute(PortableFormatterConstructorContext)

Methods

Name Description
Finalize()

Destructor.

OnAddHandler(EventInterceptionArgs)
OnInvokeHandler(EventInterceptionArgs)
OnRemoveHandler(EventInterceptionArgs)
RuntimeInitialize(EventInfo)

Explicit Interface Implementations

Name Description
IInstanceScopedAspect.CreateInstance(AdviceArgs)
IInstanceScopedAspect.RuntimeInitializeInstance()