Table of Contents

Class SafeEventHandlerSampSharpEnvironmentExtensions

Namespace
SampSharp.Entities
Assembly
SampSharp.OpenMp.Entities.dll

Provides extension methods for safely adding event handlers to components within a SampSharpEnvironment.

public static class SafeEventHandlerSampSharpEnvironmentExtensions
Inheritance
SafeEventHandlerSampSharpEnvironmentExtensions
Inherited Members

Methods

AddEventHandler<TEventHandler>(SampSharpEnvironment, Func<ICore, IEventDispatcher<TEventHandler>>, TEventHandler, EventPriority)

Adds an event handler to the core.

public static IDisposable AddEventHandler<TEventHandler>(this SampSharpEnvironment environment, Func<ICore, IEventDispatcher<TEventHandler>> dispatcherProvider, TEventHandler handler, EventPriority priority = EventPriority.Default) where TEventHandler : class, IEventHandler<TEventHandler>

Parameters

environment SampSharpEnvironment
dispatcherProvider Func<ICore, IEventDispatcher<TEventHandler>>

A function that provides the event dispatcher from the ICore.

handler TEventHandler

The event handler instance to add to the core.

priority EventPriority

The priority with which the event handler should be registered. The default is Default.

Returns

IDisposable

An IDisposable representing the event handler registration.

Type Parameters

TEventHandler

The type of the event handler.

Exceptions

InvalidOperationException

Thrown if the core does not exist, the dispatcher cannot be retrieved, or the event handler could not be added.

AddEventHandler<TComponent, TEventHandler>(SampSharpEnvironment, Func<TComponent, IEventDispatcher<TEventHandler>>, TEventHandler, EventPriority)

Adds an event handler to the specified component.

public static IDisposable AddEventHandler<TComponent, TEventHandler>(this SampSharpEnvironment environment, Func<TComponent, IEventDispatcher<TEventHandler>> dispatcherProvider, TEventHandler handler, EventPriority priority = EventPriority.Default) where TComponent : unmanaged, IComponent.IManagedInterface where TEventHandler : class, IEventHandler<TEventHandler>

Parameters

environment SampSharpEnvironment
dispatcherProvider Func<TComponent, IEventDispatcher<TEventHandler>>

A function that provides the event dispatcher from the specified TComponent.

handler TEventHandler

The event handler instance to add to the component.

priority EventPriority

The priority with which the event handler should be registered. The default is Default.

Returns

IDisposable

An IDisposable representing the event handler registration.

Type Parameters

TComponent

The type of the component to which the event handler will be added.

TEventHandler

The type of the event handler.

Exceptions

InvalidOperationException

Thrown if the component does not exist, the dispatcher cannot be retrieved, or the event handler could not be added.

TryAddEventHandler<TEventHandler>(SampSharpEnvironment, Func<ICore, IEventDispatcher<TEventHandler>>, TEventHandler, EventPriority)

Attempts to add an event handler to the core.

public static IDisposable? TryAddEventHandler<TEventHandler>(this SampSharpEnvironment environment, Func<ICore, IEventDispatcher<TEventHandler>> dispatcherProvider, TEventHandler handler, EventPriority priority = EventPriority.Default) where TEventHandler : class, IEventHandler<TEventHandler>

Parameters

environment SampSharpEnvironment
dispatcherProvider Func<ICore, IEventDispatcher<TEventHandler>>

A function that provides the event dispatcher from the ICore.

handler TEventHandler

The event handler instance to add to the core.

priority EventPriority

The priority with which the event handler should be registered. The default is Default.

Returns

IDisposable

An IDisposable representing the event handler registration, or null if the registration failed.

Type Parameters

TEventHandler

The type of the event handler.

TryAddEventHandler<TComponent, TEventHandler>(SampSharpEnvironment, Func<TComponent, IEventDispatcher<TEventHandler>>, TEventHandler, EventPriority)

Attempts to add an event handler to the specified component.

public static IDisposable? TryAddEventHandler<TComponent, TEventHandler>(this SampSharpEnvironment environment, Func<TComponent, IEventDispatcher<TEventHandler>> dispatcherProvider, TEventHandler handler, EventPriority priority = EventPriority.Default) where TComponent : unmanaged, IComponent.IManagedInterface where TEventHandler : class, IEventHandler<TEventHandler>

Parameters

environment SampSharpEnvironment
dispatcherProvider Func<TComponent, IEventDispatcher<TEventHandler>>

A function that provides the event dispatcher for the specified component.

handler TEventHandler

The event handler instance to add to the component.

priority EventPriority

The priority with which the event handler should be registered. The default is Default.

Returns

IDisposable

An IDisposable representing the event handler registration, or null if the registration failed.

Type Parameters

TComponent

The type of the component to which the event handler will be added.

TEventHandler

The type of the event handler.