Metalama 1.0 / / Metalama Documentation / Aspect API Documentation / Metalama.​Framework.​Advising / IAdvice­Factory / Introduce­Event

Method IntroduceEvent

IntroduceEvent(INamedType, String, IntroductionScope, OverrideStrategy, Action<IEventBuilder>, Object)

Introduces a new event to the target type, or overrides the implementation of an existing one, by specifying an event template.

Declaration
IIntroductionAdviceResult<IEvent> IntroduceEvent(INamedType targetType, string eventTemplate, IntroductionScope scope, OverrideStrategy whenExists, Action<IEventBuilder> buildEvent = null, object tags = null)
Parameters
Type Name Description
INamedType targetType

The type into which the event must be introduced.

String eventTemplate

The name of the event in the aspect class that must be used as a template for the introduced event. This event must be annotated with TemplateAttribute. The type of the template event can be any delegate type. The type of the introduced event can be changed dynamically thanks to the IEventBuilder returned by this method.

IntroductionScope scope

Determines the scope (e.g. Instance or Static) of the introduced event. The default scope depends on the scope of the template event. If the event is static, the introduced event is static. However, if the template event is non-static, then the introduced event copies of the scope of the target declaration of the aspect.

OverrideStrategy whenExists

Determines the implementation strategy when an event of the same name is already declared in the target type. The default strategy is to fail with a compile-time error.

Action<IEventBuilder> buildEvent
Object tags

An optional opaque object of anonymous type passed to the template event and exposed under the Tags property of the meta API.

Returns
Type Description
IIntroductionAdviceResult<IEvent>

An IEventBuilder that allows to change the name and the type of the event.

See Also

IntroduceEvent(INamedType, String, String, String, String, IntroductionScope, OverrideStrategy, Action<IEventBuilder>, Object, Object)

Introduces a new event to the target type, or overrides the implementation of an existing one, by specifying individual template methods for the adder, the remover, and the raiser.

Declaration
IIntroductionAdviceResult<IEvent> IntroduceEvent(INamedType targetType, string eventName, string addTemplate, string removeTemplate, string raiseTemplate = null, IntroductionScope scope, OverrideStrategy whenExists, Action<IEventBuilder> buildEvent = null, object args = null, object tags = null)
Parameters
Type Name Description
INamedType targetType

The type into which the event must be introduced.

String eventName

The name of the introduced event.

String addTemplate

The name of the method of the aspect class whose type and implementation will be used as a template for the adder. This method must be annotated with TemplateAttribute. The signature of this method must be void Add(T value) where T is either dynamic or a type compatible with the type of the event.

String removeTemplate

The name of the method of the aspect class whose type and implementation will be used as a template for the remover. This method must be annotated with TemplateAttribute. The signature of this method must be void Add(T value) where T is either dynamic or a type compatible with the type of the event.

String raiseTemplate

Not implemented.

IntroductionScope scope

Determines the scope (e.g. Instance or Static) of the introduced event. The default scope depends on the scope of the template event. If the event is static, the introduced event is static. However, if the template event is non-static, then the introduced event copies of the scope of the target declaration of the aspect.

OverrideStrategy whenExists

Determines the implementation strategy when an event of the same name is already declared in the target type. The default strategy is to fail with a compile-time error.

Action<IEventBuilder> buildEvent
Object args

An object (typically of anonymous type) whose properties map to parameters or type parameters of the template methods.

Object tags

An optional opaque object of anonymous type passed to the template method and exposed under the Tags property of the meta API.

Returns
Type Description
IIntroductionAdviceResult<IEvent>

An IEventBuilder that allows to change the name and the type of the event.

See Also