Exemplo n.º 1
0
        //----------------------------------------------------------------//

        public async static Task <List <T> > LoadCollection <T>(string url) where T : class, new()
        {
            List <T>       collectionDTOs = null;
            IJSONFormatter formatter      = JSONFormatterFactory.CreateJsonFormatter <T>();

            using (HttpClient client = new HttpClient())
            {
                HttpResponseMessage message = await client.GetAsync(url);

                string json = await message.Content.ReadAsStringAsync();

                collectionDTOs = formatter.DeserializeCollection <T>(json);
            }
            return(collectionDTOs);
        }
Exemplo n.º 2
0
        //----------------------------------------------------------------//

        public async static Task <T> LoadEntity <T>(string url) where T : class, new()
        {
            T dto = default(T);
            IJSONFormatter formatter = JSONFormatterFactory.CreateJsonFormatter <T>();

            using (HttpClient client = new HttpClient())
            {
                HttpResponseMessage message = await client.GetAsync(url);

                string json = await message.Content.ReadAsStringAsync();

                dto = formatter.Deserialize <T>(json);
            }
            return(dto);
        }