Open sandboxFocus

Class EventBroker<TDelegate, TArgs, TState>

Manages event handlers for event override advice when raise templates are specified. Provides thread-safe operations for adding/removing handlers and event invocation.

Inheritance
EventBroker<TDelegate, TArgs, TState>
Namespace: Metalama.Framework.RunTime.Events
Assembly: Metalama.Framework.dll
Syntax
public sealed class EventBroker<TDelegate, TArgs, TState> where TDelegate : Delegate
Type Parameters
Name Description
TDelegate

The event delegate type.

TArgs

The event arguments type (i.e. the arguments of TDelegate packed as a tuple).

TState

An opaque state stored by the EventBroker<TDelegate, TArgs, TState> and passed along to the IEventAdapter<TDelegate, TArgs, TState>. For instance events, typically set to the declaring type of the event. For static events, it is typically set to None.

Properties

Name Description
InvocationDelegate

Gets a delegate that calls the Invoke(in TArgs) method.

Methods

Name Description
AddHandler(TDelegate?)

Adds an event handler.

Invoke(in TArgs)

Invokes all registered event handlers. This method should be used when all delegate parameters are read-only and the delegate has a void return type.

InvokeByRef(ref TArgs)

Invokes all registered event handlers. This method should be used when the delegate has out or ref parameters or has a non-void return type. In the latter case, the return value must be mapped as a tuple element.

RemoveHandler(TDelegate?)

Removes an event handler.

Operators

Name Description
implicit operator TDelegate(EventBroker<TDelegate, TArgs, TState>)

Implicitly converts the broker to its delegate type.

Extension Methods