Пример #1
0
        internal RestResponse <T> Deserialize <T>(RestRequest request, RestResponse response)
        {
            request.OnBeforeDeserialization(response);

            RestResponse <T> restresponse = new RestResponse <T>
            {
                ErrorMessage      = response.ErrorMessage,
                ErrorException    = response.ErrorException,
                RawBytes          = response.RawBytes,
                ResponseStatus    = response.ResponseStatus,
                StatusCode        = response.StatusCode,
                StatusDescription = response.StatusDescription
            };

            try
            {
                // Only attempt to deserialize if the request has not errored due
                // to a transport or framework exception.  HTTP errors should attempt to
                // be deserialized

                if (response.ResponseStatus == ResponseStatus.Completed && response.ErrorException == null && response.RawBytes != null && response.RawBytes.Length > 0)
                {
                    JsonDeserializer deserializer = new JsonDeserializer();
                    restresponse.Data = deserializer.Deserialize <T>(response);
                }
            }
            catch (Exception ex)
            {
                restresponse.ResponseStatus = ResponseStatus.Error;
                restresponse.ErrorMessage   = ex.Message;
                restresponse.ErrorException = ex;
            }

            return(restresponse);
        }