Beispiel #1
0
        /// <summary>
        /// Creates a new <see cref="NntpArticle"/> object.
        /// </summary>
        /// <param name="number">The number of the <see cref="NntpArticle"/>.</param>
        /// <param name="messageId">The <see cref="NntpMessageId"/> of the <see cref="NntpArticle"/>.</param>
        /// <param name="groups">The NNTP newsgroups this <see cref="NntpArticle"/> is posted in.</param>
        /// <param name="headers">The headers of the <see cref="NntpArticle"/>.</param>
        /// <param name="body">The body of the <see cref="NntpArticle"/>.</param>
        public NntpArticle(
            long number,
            NntpMessageId messageId,
            NntpGroups groups,
            IDictionary <string, ICollection <string> > headers,
            IEnumerable <string> body)
        {
            Number    = number;
            MessageId = messageId ?? NntpMessageId.Empty;
            Groups    = groups ?? NntpGroups.Empty;
            Headers   = (headers ?? MultiValueDictionary <string, string> .Empty).ToImmutableDictionaryWithHashSets();

            switch (body)
            {
            case null:
                // create empty immutable list
                Body = new List <string>(0).ToImmutableList();
                break;

            case ICollection <string> collection:
                // make immutable
                Body = collection.ToImmutableList();
                break;

            default:
                // not a collection but a stream of lines, keep enumerator
                // this is immutable already
                Body = body;
                break;
            }
        }