/// <summary>
        /// Возвращает форму запроса.
        /// </summary>
        protected TDocument ReadRequestForm <TDocument>(IHttpRequest request, string documentFormKey)
        {
            if (request.Headers.ContentType.StartsWith(HttpConstants.MultipartFormDataContentType, StringComparison.OrdinalIgnoreCase) ||
                request.Headers.ContentType.StartsWith(HttpConstants.FormUrlencodedContentType, StringComparison.OrdinalIgnoreCase))
            {
                if (request.Form != null)
                {
                    var documentString = (string)request.Form[documentFormKey];

                    if (!string.IsNullOrWhiteSpace(documentString))
                    {
                        return(_objectSerializer.Deserialize <TDocument>(documentString));
                    }
                }
            }
            else if (request.Headers.ContentType.StartsWith(HttpConstants.JsonContentType, StringComparison.OrdinalIgnoreCase))
            {
                if (request.Form != null)
                {
                    return(_objectSerializer.ConvertFromDynamic <TDocument>((object)request.Form));
                }
            }
            else if (request.Content != null)
            {
                return(_objectSerializer.Deserialize <TDocument>(request.Content));
            }

            return(default(TDocument));
        }
        public async Task <T> GetAsync <T>(string requestUri)
        {
            var response = await Client.GetAsync(requestUri);

            var stream = await response.Content.ReadAsStreamAsync();

            return(_serializer.Deserialize <T>(stream));
        }
        private object ParseRequestForm()
        {
            var method = _nancyRequest.Method;

            if (string.Equals(method, "POST", StringComparison.OrdinalIgnoreCase) ||
                string.Equals(method, "PUT", StringComparison.OrdinalIgnoreCase) ||
                string.Equals(method, "PATCH", StringComparison.OrdinalIgnoreCase))
            {
                var contentType = _nancyRequest.Headers.ContentType;

                if (contentType != null && contentType.StartsWith(HttpConstants.JsonContentType, StringComparison.OrdinalIgnoreCase))
                {
                    return(_jsonObjectSerializer.Deserialize(_nancyRequest.Body, typeof(DynamicWrapper)));
                }
            }

            return(_nancyRequest.Form);
        }
Example #4
0
 public static T Deserialize <T>(this IJsonObjectSerializer target, string data)
 {
     return((T)target.Deserialize(data, typeof(T)));
 }