3.3 KiB
3.3 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |
|---|---|---|---|---|---|
|
2026-04-17T16:11:20.602481+00:00 | zai-org/GLM-5-FP8 | 1 | bb36e013f0f39c56 |
EventManager
Purpose
This module implements a type-safe, loosely-coupled publish/subscribe event system. It allows components to communicate without direct references to each other, supporting filtered subscriptions and diagnostic monitoring of event flow. This decouples publishers from subscribers and centralizes event routing.
Public Interface
EventManager (static class)
static void Publish<T>(T eventData) where T : class— Publishes an event to all subscribers of typeT. If no subscribers exist, returns immediately. Each subscriber's filter (if present) is evaluated before invoking the callback.static void Subscribe<T>(SubscriberCallbackDelegate<T> listener) where T : class— Subscribes to events of typeTwithout a filter.static void Subscribe<T>(SubscriberCallbackDelegate<T> listener, Predicate<T> eventFilter) where T : class— Subscribes to events of typeTwith a filter predicate. The callback is only invoked when the filter returnstrue.static void UnSubscribe<T>(SubscriberCallbackDelegate<T> listener) where T : class— Removes all subscriptions matching the given listener delegate.static void Clear()— Removes all subscribers from all event types.static void SubscribeToDiagnosticEvents(DiagnosticCallbackDelegate listener)— Registers a callback to receive diagnostic events about the event system itself.static void UnSubscribeToDiagnosticEvents(DiagnosticCallbackDelegate listener)— Removes a diagnostic listener.static void ClearDiagnosticEvents()— Removes all diagnostic listeners.
SubscriberCallbackDelegate<in T> (delegate)
void SubscriberCallbackDelegate<in T>(T item) where T : class— The signature for event callbacks.
DiagnosticCallbackDelegate (delegate)
void DiagnosticCallbackDelegate(EventDiagnosticType eventType, Type t, object eventData, string listener)— The signature for diagnostic callbacks.
EventDiagnosticType (enum)
- Values:
AddListener = 0,AddListenerDiagnostic = 1,PublishEvent = 2,RemoveListenerDiagnostic = 3,RemoveListener = 4
Invariants
SubscriberListandDiagnosticListare never null (initialized inline).Publish<T>silently does nothing if no subscribers exist for typeT.- Subscribers are stored in insertion order; callbacks are invoked in that order during
Publish. UnSubscribe<T>removes all matching entries (not just the first).EventMetaData<T>is internal and always contains a non-nullCallbackafter construction.
Dependencies
- Depends on:
System,System.Collections.Generic,System.Reflection. - Depended on by: Unknown from source alone—likely used throughout the application for cross-component communication.
Gotchas
- Subscribers hold references to callbacks. If a subscriber fails to call
UnSubscribe, the callback (and potentially its capturing object) will not be garbage collected, causing memory leaks. Publishiterates overlistenersdirectly; if a callback modifies the subscriber list (e.g., by callingSubscribeorUnSubscribe), behavior is undefined (likely an exception or skipped