Click or drag to resize
DigitalRuneWeakEventHandlerTEventArgsRegisterTSender, TListener Method
Registers an event handler that works with a weak reference to the target object.

Namespace: DigitalRune
Assembly: DigitalRune (in DigitalRune.dll) Version: 1.20.0.0 (1.20.1.14552)
Syntax
public static IDisposable Register<TSender, TListener>(
	TSender sender,
	TListener listener,
	Action<TSender, EventHandler<TEventArgs>> addHandler,
	Action<TSender, EventHandler<TEventArgs>> removeHandler,
	Action<TListener, Object, TEventArgs> forwardEvent
)
where TSender : class
where TListener : class

Parameters

sender
Type: TSender
The object that provides the event.
listener
Type: TListener
The object that listens to the event.
addHandler
Type: SystemActionTSender, EventHandlerTEventArgs
A callback method that adds an event handler to the event.
removeHandler
Type: SystemActionTSender, EventHandlerTEventArgs
A callback method that removes an event handler from the event.
forwardEvent
Type: SystemActionTListener, Object, TEventArgs
A callback method that forwards the event to the actual event handler.

Type Parameters

TSender
The type of the sender.
TListener
The type of the listener.

Return Value

Type: IDisposable
An IDisposable which can be used to detach the weak event handler from the event.
Exceptions
ExceptionCondition
ArgumentNullExceptionsender, addHandler, removeHandler, listener, or forwardEvent is .
Remarks
Access to the event and to the real event handler is done through lambda expressions. The code holds strong references to these expressions, so they must not capture any variables of the target object (listener)!
Examples
C#
WeakEventHandler<DocumentChangeEventArgs>.Register(
   textDocument,
   this,
   (sender, eventHandler) => sender.Changed += eventHandler,
   (sender, eventHandler) => sender.Changed -= eventHandler,
   (listener, sender, eventArgs) => listener.OnDocumentChanged(sender, eventArgs));
See Also