Skip to main content

ComponentEventSubscriber

A class in Root.Township, the global namespace.

Subscribes a component's handler to an event and unsubscribes itself, with an error log, if the component has been destroyed when the event fires. Dispose to unsubscribe.

Constructors​

MemberWhat it is
ComponentEventSubscriber(Component component, Func<Action, Action> subscriber, Action<Action> unsubscriber)Creates a ComponentEventSubscriber from component, subscriber and unsubscriber.

Fields​

5 private and internal fields
MemberWhat it is
private readonly Action actionThe handler returned by the subscribe call, run when the event fires.
private static readonly Logger loggerNLog logger for this class.
private readonly Component ownerThe component the subscription belongs to.
private string pathHierarchy path of owner, saved for the error message.
private readonly Action<Action> unsubscribeDelegate that removes the subscription.

Methods​

MemberWhat it is
void Dispose()Unsubscribes from the event.
2 private and internal methods
MemberWhat it is
private void Invoke()Runs the action, or unsubscribes and logs an error if the owning object has been destroyed.
private void UpdatePath()Stores the component's full hierarchy path, used in the error log.

Used in​

Members of other types that take, return or hold a ComponentEventSubscriber: