Ejemplo n.º 1
0
            /// <summary>
            /// Gets the list of actions to be invoked for the specified message
            /// </summary>
            /// <param name="key">The message to get the actions for</param>
            /// <returns>Returns a list of actions that are registered to the specified message</returns>
            internal List <Delegate> GetActions(Type messageTargetType, string key)
            {
                if (key == null)
                {
                    throw new ArgumentNullException("message");
                }

                List <Delegate> actions;

                lock (_map)
                {
                    if (!_map.ContainsKey(key))
                    {
                        return(null);
                    }

                    List <WeakAction> weakActions = _map[key];
                    actions = new List <Delegate>(weakActions.Count);
                    for (int i = weakActions.Count - 1; i > -1; --i)
                    {
                        WeakAction weakAction = weakActions[i];
                        if (weakAction == null)
                        {
                            continue;
                        }
                        if (weakAction.Recipient.GetType() == messageTargetType)
                        {
                            continue;
                        }

                        Delegate action = weakAction.CreateAction();
                        if (action != null)
                        {
                            actions.Add(action);
                        }
                        else
                        {
                            // The target object is dead, so get rid of the weak action.
                            weakActions.Remove(weakAction);
                        }
                    }

                    // Delete the list from the map if it is now empty.
                    if (weakActions.Count == 0)
                    {
                        _map.Remove(key);
                    }
                }

                // Reverse the list to ensure the callbacks are invoked in the order they were registered.
                actions.Reverse();

                return(actions);
            }
Ejemplo n.º 2
0
            /// <summary>
            /// Gets the list of actions to be invoked for the specified message
            /// </summary>
            /// <param name="message">The message to get the actions for</param>
            /// <returns>Returns a list of actions that are registered to the specified message</returns>
            internal List <Delegate> GetActions(Enum message)
            {
                List <Delegate> actions;

                lock (_map) {
                    if (!_map.ContainsKey(message))
                    {
                        return(null);
                    }

                    Dictionary <Guid, WeakAction> weakActions = _map[message];
                    actions = new List <Delegate>(weakActions.Count);
                    foreach (var id in weakActions.Keys)
                    {
                        WeakAction weakAction = weakActions[id];
                        if (weakAction == null)
                        {
                            continue;
                        }

                        Delegate action = weakAction.CreateAction();
                        if (action != null)
                        {
                            actions.Add(action);
                        }
                        else
                        {
                            // The target object is dead, so get rid of the weak action.
                            weakActions.Remove(id);
                        }
                    }

                    // Delete the list from the map if it is now empty.
                    if (weakActions.Count == 0)
                    {
                        _map.Remove(message);
                    }
                }

                // Reverse the list to ensure the callbacks are invoked in the order they were registered.
                actions.Reverse();

                return(actions);
            }
Ejemplo n.º 3
0
            internal List <Delegate> GetActions(string message)
            {
                if (message == null)
                {
                    throw new ArgumentNullException(nameof(message));
                }
                List <Delegate> actions;

                lock (_map)
                {
                    if (!_map.ContainsKey(message))
                    {
                        return(null);
                    }
                    List <WeakAction> weakActions = _map[message];
                    actions = new List <Delegate>(weakActions.Count);
                    for (int i = weakActions.Count - 1; i >= -1 + 1; i += -1)
                    {
                        WeakAction weakAction = weakActions[i];
                        if (weakAction == null)
                        {
                            continue;
                        }
                        Delegate action = weakAction.CreateAction();
                        if (action != null)
                        {
                            actions.Add(action);
                        }
                        else
                        {
                            weakActions.Remove(weakAction);
                        }
                    }

                    // Delete the list from the map if it is now empty.
                    if (weakActions.Count == 0)
                    {
                        _map.Remove(message);
                    }
                }
                return(actions);
            }