/// <summary> /// Remove object from module_accessor /// </summary> /// <param name="theObjectScript"></param> public static void RemoveKGFObject(KGFObject theObjectScript) { // remove from list of own type System.Type anObjectScriptType = theObjectScript.GetType(); try{ itsListSorted[anObjectScriptType].Remove(theObjectScript); } catch {} // call registered events foreach (System.Type aKeyType in itsListEventsRemove.Keys) { if (aKeyType.IsAssignableFrom(anObjectScriptType)) { itsListEventsRemove[aKeyType].Trigger(null, new KGFAccessorEventargs(theObjectScript)); } } }
/// <summary> /// Add object to module_accessor /// </summary> /// <param name='theBaseScript'> /// All object_scripts will register using this method /// </param> public static void AddKGFObject(KGFObject theObjectScript) { // add to list of own type Type anObjectScriptType = theObjectScript.GetType(); if (!itsListSorted.ContainsKey(anObjectScriptType)) { itsListSorted[anObjectScriptType] = new List <KGFObject>(); } itsListSorted[anObjectScriptType].Add(theObjectScript); // call register events foreach (Type aKeyType in itsListEventsAdd.Keys) { if (aKeyType.IsAssignableFrom(anObjectScriptType)) { itsListEventsAdd[aKeyType].Trigger(null, new KGFAccessorEventargs(theObjectScript)); } } if (itsListEventsAddOnce.Count > 0) { // call register events once List <Type> aTypeList = new List <Type>(); foreach (Type aKeyType in itsListEventsAddOnce.Keys) { if (aKeyType.IsAssignableFrom(anObjectScriptType)) { aTypeList.Add(aKeyType); } } foreach (Type aType in aTypeList) { itsListEventsAddOnce[aType].Trigger(null, new KGFAccessorEventargs(theObjectScript)); itsListEventsAddOnce.Remove(aType); } } }