v3.6.1 Documentation
Fungus.EventDispatcher Class Reference

A simple efficient event dispatcher with logging support. More...

Inheritance diagram for Fungus.EventDispatcher:

Public Member Functions

delegate void TypedDelegate< T > (T e)
 A typed delegate which contains information about the event. More...
 
virtual void AddLog (Action< string > log)
 Adds a log callback action. More...
 
virtual void RemoveLog (Action< string > log)
 Removes a log callback action. More...
 
virtual void AddListener< T > (TypedDelegate< T > listener)
 Adds a listener for a specified event type. More...
 
virtual void RemoveListener< T > (TypedDelegate< T > listener)
 Removes a listener for a specified event type. More...
 
virtual void Raise< T > (T evt)
 Raise an event of a specified type. More...
 
virtual void Raise< T > ()
 Raise an event of a specified type, creates an instance of the type automatically. More...
 
virtual void UnregisterAll ()
 Unregisters all event listeners. More...
 

Protected Member Functions

virtual List< Delegate > GetDelegateListCopy< T > (T evt)
 Gets the delegate list copy. More...
 
virtual void Log (string message)
 

Protected Attributes

readonly Dictionary< Type, List< Delegate > > delegates = new Dictionary<Type, List<Delegate>>()
 

Events

virtual Action< string > onLog
 

Detailed Description

A simple efficient event dispatcher with logging support.

Definition at line 13 of file EventDispatcher.cs.

Member Function Documentation

◆ AddListener< T >()

virtual void Fungus.EventDispatcher.AddListener< T > ( TypedDelegate< T >  listener)
virtual

Adds a listener for a specified event type.

Type Constraints
T :class 

Definition at line 68 of file EventDispatcher.cs.

◆ AddLog()

virtual void Fungus.EventDispatcher.AddLog ( Action< string >  log)
virtual

Adds a log callback action.

Definition at line 52 of file EventDispatcher.cs.

◆ GetDelegateListCopy< T >()

virtual List<Delegate> Fungus.EventDispatcher.GetDelegateListCopy< T > ( evt)
protectedvirtual

Gets the delegate list copy.

As listener can modify the list while iterating it, it is better to iterate a copy of the delegates list instead of a reference.

Returns
A copy of the delegates list if found. Null if the dictionary does not contain a delegate list for this event.
Parameters
evtEvent instance.
Template Parameters
TType of the received event.

Definition at line 28 of file EventDispatcher.cs.

◆ Log()

virtual void Fungus.EventDispatcher.Log ( string  message)
protectedvirtual

Definition at line 34 of file EventDispatcher.cs.

◆ Raise< T >() [1/2]

virtual void Fungus.EventDispatcher.Raise< T > ( evt)
virtual

Raise an event of a specified type.

Type Constraints
T :class 

Definition at line 99 of file EventDispatcher.cs.

◆ Raise< T >() [2/2]

virtual void Fungus.EventDispatcher.Raise< T > ( )
virtual

Raise an event of a specified type, creates an instance of the type automatically.

Type Constraints
T :class 
T :new() 

Definition at line 135 of file EventDispatcher.cs.

◆ RemoveListener< T >()

virtual void Fungus.EventDispatcher.RemoveListener< T > ( TypedDelegate< T >  listener)
virtual

Removes a listener for a specified event type.

Type Constraints
T :class 

Definition at line 86 of file EventDispatcher.cs.

◆ RemoveLog()

virtual void Fungus.EventDispatcher.RemoveLog ( Action< string >  log)
virtual

Removes a log callback action.

Definition at line 60 of file EventDispatcher.cs.

◆ TypedDelegate< T >()

delegate void Fungus.EventDispatcher.TypedDelegate< T > ( e)

A typed delegate which contains information about the event.

Type Constraints
T :class 

◆ UnregisterAll()

virtual void Fungus.EventDispatcher.UnregisterAll ( )
virtual

Unregisters all event listeners.

Definition at line 143 of file EventDispatcher.cs.

Member Data Documentation

◆ delegates

readonly Dictionary<Type, List<Delegate> > Fungus.EventDispatcher.delegates = new Dictionary<Type, List<Delegate>>()
protected

Definition at line 15 of file EventDispatcher.cs.

Event Documentation

◆ onLog

virtual Action<string> Fungus.EventDispatcher.onLog
protected

Definition at line 17 of file EventDispatcher.cs.


The documentation for this class was generated from the following file: