Beispiel #1
0
 /// <summary>
 /// Explicitly converts from a <see cref="MessageStore{T}"/> to the encapsulated <see cref="Message"/>.
 /// </summary>
 /// <param name="store">The store to convert.</param>
 /// <returns>The encapsulated message.</returns>
 public static T FromMessageStore(MessageStore <T> store) => store?.message;
Beispiel #2
0
        /// <summary>
        /// Used to get a message from the message dictionaries.
        /// </summary>
        /// <param name="domain">The message domain to get the message for.</param>
        /// <param name="messagePool">The dictionary for the specific message type.</param>
        /// <param name="message">The message for the domain.</param>
        /// <typeparam name="T">The type of the message.</typeparam>
        /// <returns><c>true</c> if the dictionary contains a message for the specific domain; otherwise <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">If the dictionary is null.</exception>
        protected bool TryGetMessageFittingDomain <T>(MessageDomain domain, ConcurrentDictionary <MessageDomain, MessageStore <T> > messagePool, out MessageStore <T> message)
            where T : Message
        {
            if (messagePool == null)
            {
                throw new ArgumentNullException(nameof(messagePool));
            }
            MessageDomain current = domain;

            while (current != null)
            {
                if (messagePool.TryGetValue(current, out message))
                {
                    return(true);
                }
                current = current.Parent;
            }

            message = null;
            return(false);
        }