public DelegateData(Delegate del, Type delType, Type module, BuildingEvents[] ID) { delegateInstance = del; moduleType = module; eventID = ID; delegateType = delType; }
/// <summary> /// Method for adding a delegate to the collection. /// </summary> /// <param name="type">Type of the class containing the delegate</param> /// <param name="eventInfo">MethodInfo for the method to be invoked by the delegate</param> public void AddDelegate(Type type, MethodInfo eventInfo) { if (delegateNameDictionary.ContainsKey(type + "_" + eventInfo.Name)) { Debug.Log("Warning: tried to add event delegate " + eventInfo.Name + " for module " + type + ", but an entry already exists!"); return; } BuildingEvents eventID = (BuildingEvents)Enum.Parse(typeof(BuildingEvents), eventInfo.Name); var delType = EventMap[eventID]; Delegate newDelegate = Delegate.CreateDelegate(delType, eventInfo); DelegateData newDelegateData = new DelegateData(newDelegate, delType, type, eventID); delegates.Add(newDelegateData); delegateEventMapping[eventID].Add(newDelegateData); delegateNameDictionary[newDelegateData.name] = newDelegateData; }