示例#1
0
        /// <summary>
        /// Factory method that parses a given Stream with the appropriate playlist type, based on the supplied content type.
        /// </summary>
        /// <param name="contentType">Internet content type representing the playlist type of the Stream.</param>
        /// <param name="stream">Stream representing the playlist data.</param>
        /// <returns>Successfully parsed playlist.</returns>
        public static IPlaylist Parse(string contentType, Stream stream)
        {
            if (string.IsNullOrEmpty(contentType))
            {
                throw new ArgumentException("contentType cannot be null or empty.");
            }

            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            IPlaylistParser result;
            switch (contentType)
            {
                case M3uParser.M3uContentType:
                    result = new M3uParser();
                    break;
                case PlsParser.PlsContentType:
                    result = new PlsParser();
                    break;
                default:
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Invalid content type: {0}", contentType));
            }

            return result.Parse(stream);
        }
        /// <summary>
        /// Factory method that parses a given Stream with the appropriate playlist type, based on the supplied content type.
        /// </summary>
        /// <param name="contentType">Internet content type representing the playlist type of the Stream.</param>
        /// <param name="stream">Stream representing the playlist data.</param>
        /// <returns>Successfully parsed playlist.</returns>
        public static IPlaylist Parse(string contentType, Stream stream)
        {
            if (string.IsNullOrEmpty(contentType))
            {
                throw new ArgumentException("contentType cannot be null or empty.");
            }

            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            IPlaylistParser result;

            switch (contentType)
            {
            case M3uParser.M3uContentType:
                result = new M3uParser();
                break;

            case PlsParser.PlsContentType:
                result = new PlsParser();
                break;

            default:
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Invalid content type: {0}", contentType));
            }

            return(result.Parse(stream));
        }