コード例 #1
0
        /// <summary>
        /// Gets one or more media templates in the collection that match the <paramref name="mimeType" />. If no item is found, then
        /// the MIME type that matches the major portion is returned. For example, if the collection does not contain a specific item
        /// for "image/jpeg", then the MIME type for "image/*" is returned. This method returns multiple items when more than one
        /// template has been specified for browsers. That is, all returned items will have the same value for
        /// <see cref="IMediaTemplate.MimeType" /> but the <see cref="IMediaTemplate.BrowserId" /> property will vary. At least one
        /// item in the collection will have the <see cref="IMediaTemplate.BrowserId" /> property set to "default". Guaranteed to not
        /// return null. If no items are found (which shouldn't happen), an empty collection is returned.
        /// </summary>
        /// <param name="mimeType">The MIME type for which to retrieve matching media templates.</param>
        /// <returns>Returns a <see cref="IMediaTemplateCollection" /> containing media templates that match the
        /// <paramref name="mimeType" />. </returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="mimeType" /> is null.</exception>
        public IMediaTemplateCollection Find(IMimeType mimeType)
        {
            if (mimeType == null)
            {
                throw new ArgumentNullException("mimeType");
            }

            IMediaTemplateCollection copy = new MediaTemplateCollection();

            string fullType = mimeType.FullType;

            foreach (var item in (List <IMediaTemplate>)Items)
            {
                if (item.MimeType.Equals(fullType, StringComparison.OrdinalIgnoreCase))
                {
                    copy.Add(item);
                }
            }

            if (!HasDefaultTemplate(copy))
            {
                // No specific MIME type was found (such as "video/mp4"), or one was found but it
                // didn't have a default variant. Find the generic ones (such as "video/*").
                string genericMimeType = String.Concat(mimeType.MajorType, "/*");
                foreach (var item in (List <IMediaTemplate>)Items)
                {
                    if (item.MimeType.Equals(genericMimeType, StringComparison.OrdinalIgnoreCase))
                    {
                        copy.Add(item);
                    }
                }
            }

            return(copy);
        }
コード例 #2
0
        /// <summary>
        /// Creates a deep copy of this instance.
        /// </summary>
        /// <returns>Returns a deep copy of this instance.</returns>
        public IMediaTemplateCollection Copy()
        {
            IMediaTemplateCollection copy = new MediaTemplateCollection();

            foreach (var item in (List <IMediaTemplate>)Items)
            {
                copy.Add(item.Copy());
            }

            return(copy);
        }