// unloadSeries /// Unloads a series of handlers with the same guid /////////////////////////////////////////////////// public void unloadSeries(string guid) { //Be threadsafe using (DdMonitor.Lock(m_eventobject._sync)) { //Search through all our events foreach (KeyValuePair <string, HandlerList> kvp in this) { //For each handler List <CEventHandler> toRemove = new List <CEventHandler>(); foreach (CEventHandler eh in kvp.Value.methods) { //If the handler is in this series if (eh.guid == guid) { //Add it to the removal list toRemove.Add(eh); } } //Remove all condemned handlers foreach (CEventHandler eh in toRemove) { kvp.Value.methods.Remove(eh); } } } }
/// <summary> /// Calls a singlecast event, returning a value /// </summary> static public object callsync(IEventObject obj, string name, bool bSync, params object[] args) { //Play safe? if (bSync) { using (DdMonitor.Lock(obj._sync)) { //Does the event exist? HandlerList list; if (!obj.events.TryGetValue(name, out list)) { //No? No need to worry return(null); } //Got it! Execute all handlers foreach (CEventHandler eh in list.methods) { //Sanity checks if (eh.argnum != args.Length) { throw new ArgumentException("Parameter mismatch while attempting to invoke custom event '" + name + "'"); } //We're ok, time to invoke it object ret = null; //Use the logger if necessary using (LogAssume.Assume(obj._eventLogger)) { //Custom handler? if (eh.customcaller == null) { ret = eh.handler(eh.that, args); } else { //Allow them to call it ret = eh.customcaller(eh, true, eh.that, args); } //Got our loot, return with it return(ret); } } return(null); } } else { //Does the event exist? HandlerList list; if (!obj.events.TryGetValue(name, out list)) { //No? No need to worry return(null); } //Got it! Execute all handlers foreach (CEventHandler eh in list.methods) { //Sanity checks if (eh.argnum != args.Length) { throw new ArgumentException("Parameter mismatch while attempting to invoke custom event '" + name + "'"); } //We're ok, time to invoke it object ret = null; //Use the logger if necessary using (LogAssume.Assume(obj._eventLogger)) { //Custom handler? if (eh.customcaller == null) { ret = eh.handler(eh.that, args); } else { //Allow them to call it ret = eh.customcaller(eh, true, eh.that, args); } //Got our loot, return with it return(ret); } } return(null); } }