Example #1
0
        public static T ConvertFrom <T>([NotNull] this WebClient client, Uri url)
            where T : class
        {
            client = client.ArgumentNotNull();
            url    = url.ArgumentNotNull();

            var data = client.DownloadString(url);

            if (string.IsNullOrEmpty(data))
            {
                return(null);
            }

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(data)))
            {
                var serializer = new DataContractJsonSerializer(typeof(T));
                var obj        = (T)serializer.ReadObject(stream);

                stream.FlushClose();

                return(obj);
            }
        }