Ear cleanup.
3 using System.Collections.Generic;
4 using System.ComponentModel;
6 using System.Reflection;
7 using System.Runtime.Serialization;
10 namespace SharpLib.Ear
13 /// Event Action Router (Ear) is a generic and extensible framework allowing users to execute actions in response to events.
14 /// Users can implement their own events and actions.
16 [TypeConverter(typeof(TypeConverterJson<Manager>))]
21 /// Access the currently installed EAR manager.
23 public static Manager Current = null;
26 /// Our events instances.
29 public List<Event> Events;
40 /// Executes after internalization took place.
46 Events = new List<Event>();
52 /// Trigger the given event.
54 /// <param name="aEventType"></param>
55 public void TriggerEvent<T>() where T: class
57 //Only trigger enabled events matching the desired type
58 foreach (Event e in Events.Where(e => e.GetType() == typeof(T) && e.Enabled))
66 /// Remove the specified action from the event it belongs too.
68 /// <param name="aAction"></param>
69 public void RemoveAction(Action aAction)
71 foreach (Event e in Events)
73 if (e.Actions.Remove(aAction))
75 //We removed our action, we are done here.