Created
July 21, 2013 18:23
-
-
Save renatocantarino/6049404 to your computer and use it in GitHub Desktop.
Helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net; | |
namespace OpenMVC.Helpers | |
{ | |
public class Builder | |
{ | |
public static T Download_And_Serialize_Data<T>(string url) where T : new() | |
{ | |
using (var w = new WebClient()) | |
{ | |
var json_data = string.Empty; | |
try | |
{ | |
json_data = w.DownloadString(url); | |
} | |
catch (Exception) | |
{ | |
} | |
return !string.IsNullOrEmpty(json_data) ? Newtonsoft.Json.JsonConvert.DeserializeObject<T>(json_data) : new T(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment