Пример #1
0
 /// <summary>
 /// Deserialize the JSON string into an object of type <typeparamref name = "T" />.
 /// </summary>
 /// <typeparam name="T">The type of object to deserialize to.</typeparam>
 /// <param name="value">A string with the data to be deserialized.
 /// If string is empty, than default(T) will be returned.</param>
 public static T?JsonToObject <T>(this string?value)
 {
     if (string.IsNullOrEmpty(value))
     {
         return(default(T));
     }
     return(RestHttpClientSerializer.Deserialize <T>(value));
 }
Пример #2
0
        static async Task <HttpResponseMessage> MakeRequest(HttpClient httpClient, string requestType, string uri, object value)
        {
            var cts = new CancellationTokenSource();

            cts.CancelAfter(httpClient.Timeout);

            var method = new HttpMethod(requestType);

            var serializedRequestValue = RestHttpClientSerializer.Serialize(value);
            var request = new HttpRequestMessage(method, uri)
            {
                Content = new StringContent(serializedRequestValue, Encoding.UTF8, "application/json")
            };

            return(await httpClient.SendAsync(request, cts.Token));
        }