// TODO: Try to remove or make internal somehow...? public void RemoveListener(object context) { List <string> toRemoKeys = new List <string>(); // Removing all event handler with the given context (object instance) foreach (string idx in InstanceMethod.Keys) { List <Tuple <MethodInfo, object> > idxCur = InstanceMethod[idx]; List <Tuple <MethodInfo, object> > toRemove = new List <Tuple <MethodInfo, object> >(); foreach (Tuple <MethodInfo, object> idxObj in idxCur) { if (idxObj.Item2 == context) { toRemove.Add(idxObj); } } foreach (Tuple <MethodInfo, object> idxObj in toRemove) { idxCur.Remove(idxObj); if (idxCur.Count == 0) { toRemoKeys.Add(idx); } } } foreach (string idx in toRemoKeys) { InstanceMethod.Remove(idx); } }