Open sandboxFocus

Interface IEventInvoker

Allows generating run-time code that adds handlers to, removes handlers from, or raises an event when you have its compile-time IEvent representation.

Namespace: Metalama.Framework.Code.Invokers
Assembly: Metalama.Framework.dll
Syntax
[CompileTime]
public interface IEventInvoker
Remarks

Invokers are APIs that allow you to generate run-time code from compile-time declarations. When you have an IEvent object (a compile-time representation of an event), you can use its invoker methods to create expressions that add or remove event handlers, or raise the event. These operations can then be used in templates and will be expanded into actual C# code.

The Add(dynamic?) and Remove(dynamic?) methods generate code to manage event handlers, while Raise(params dynamic?[]) generates code to invoke the event. Use WithObject(dynamic?) to specify the target instance and WithOptions(InvokerOptions) to control nullability behavior and which implementation layer (base, current, or final) to access.

By default, the event is accessed on the current object (this) for instance events. The base implementation is accessed, i.e. the implementation before the current aspect layer.

Methods

Name Description
Add(IExpression)

Generates run-time code that adds a handler, given as an IExpression, to the event.

Add(dynamic?)

Generates run-time code that adds a handler, given as run-time C# expression, to the event.

Raise(params IExpression[])

Generates run-time code that raises the current event with arguments specified as compile-time IExpression objects.

Raise(params dynamic?[])

Generates run-time code that raises the current event with arguments specified as run-time C# expressions.

Remove(IExpression)

Generates run-time code that removes a handler, given as an IExpression, from the event.

Remove(dynamic?)

Generates run-time code that removes a handler, given a run-time C# expression, from the event.

With(InvokerOptions)
With(dynamic?, InvokerOptions)
WithObject(IExpression?)

Gets an IEventInvoker for the same event but with a different object, specified as a compile-time IExpression object.

WithObject(dynamic?)

Gets an IEventInvoker for the same event but with a different object, specified as a run-time C# expression.

WithOptions(InvokerOptions)

Gets an IEventInvoker for the same event and target but with different options.

Extension Methods

See Also