Class SafeEventHandlerSampSharpEnvironmentExtensions
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
environmentSampSharpEnvironmentdispatcherProviderFunc<ICore, IEventDispatcher<TEventHandler>>A function that provides the event dispatcher from the ICore.
handlerTEventHandlerThe event handler instance to add to the core.
priorityEventPriorityThe priority with which the event handler should be registered. The default is Default.
Returns
- IDisposable
An IDisposable representing the event handler registration.
Type Parameters
TEventHandlerThe 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
environmentSampSharpEnvironmentdispatcherProviderFunc<TComponent, IEventDispatcher<TEventHandler>>A function that provides the event dispatcher from the specified
TComponent.handlerTEventHandlerThe event handler instance to add to the component.
priorityEventPriorityThe priority with which the event handler should be registered. The default is Default.
Returns
- IDisposable
An IDisposable representing the event handler registration.
Type Parameters
TComponentThe type of the component to which the event handler will be added.
TEventHandlerThe 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
environmentSampSharpEnvironmentdispatcherProviderFunc<ICore, IEventDispatcher<TEventHandler>>A function that provides the event dispatcher from the ICore.
handlerTEventHandlerThe event handler instance to add to the core.
priorityEventPriorityThe 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
TEventHandlerThe 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
environmentSampSharpEnvironmentdispatcherProviderFunc<TComponent, IEventDispatcher<TEventHandler>>A function that provides the event dispatcher for the specified component.
handlerTEventHandlerThe event handler instance to add to the component.
priorityEventPriorityThe 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
TComponentThe type of the component to which the event handler will be added.
TEventHandlerThe type of the event handler.