コード例 #1
0
        /// <summary>
        /// Deserialize the content from the stream.
        /// </summary>
        /// <param name="contentType">Used to identify the object which is about to be deserialized. Specified by the <c>Serialize()</c> method when invoked in the other end point.</param>
        /// <param name="source">Stream that contains the object to deserialize.</param>
        /// <returns>Created object</returns>
        /// <exception cref="SerializationException">Deserialization failed</exception>
        public object Deserialize(string contentType, Stream source)
        {
            if (contentType == null)
            {
                throw new ArgumentNullException("contentType");
            }
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (!contentType.StartsWith(MimeType))
            {
                return(null);
            }

            try
            {
                var result = new FormAndFilesResult()
                {
                    Form = new ParameterCollection()
                };
                var decoder = new UrlDecoder();
                decoder.Parse(new StreamReader(source), result.Form);
                source.Position = 0;
                return(result);
            }
            catch (ArgumentException err)
            {
                throw new Exception(err.Message, err);
            }
        }
コード例 #2
0
        /// <summary>
        /// Deserialize the content from the stream.
        /// </summary>
        /// <param name="contentType">Used to identify the object which is about to be deserialized. Specified by the <c>Serialize()</c> method when invoked in the other end point.</param>
        /// <param name="source">Stream that contains the object to deserialize.</param>
        /// <returns>Created object</returns>
        /// <exception cref="SerializationException">Deserialization failed</exception>
        public object Deserialize(string contentType, Stream source)
        {
            if (contentType == null) throw new ArgumentNullException("contentType");
            if (source == null) throw new ArgumentNullException("source");

            if (!contentType.StartsWith(MimeType))
                return null;

            try
            {
                var result = new FormAndFilesResult()
                {
                    Form = new ParameterCollection()
                };
                var decoder = new UrlDecoder();
                decoder.Parse(new StreamReader(source), result.Form);
                source.Position = 0;
                return result;
            }
            catch (ArgumentException err)
            {
                throw new Exception(err.Message, err);
            }
        }