Exemplo n.º 1
0
        public T DeserialiseResponseBody <T>( )
        {
            if (HttpWebResponse == null)
            {
                throw new InvalidOperationException("No web response is available; have you submitted your web request?");
            }

            var stream = HttpWebResponse.GetResponseStream( );

            if (stream == null)
            {
                throw new InvalidOperationException("No web response stream is available; have you submitted your web request?");
            }

            T obj;

            if (!stream.CanSeek || stream.Length > 0)
            {
                var reader           = new StreamReader(stream);
                var responseAsString = reader.ReadToEnd( );
                obj = JSON.Deserialize <T>(responseAsString, Options);

                if (typeof(T) == typeof(HttpError))
                {
                    var existingError = obj as HttpError;

                    if (existingError != null)
                    {
                        obj = ( T )( object )ExceptionFilter.DeserializeHttpError(existingError);
                    }
                }
            }
            else
            {
                obj = default(T);
            }

            return(obj);
        }