I'm having to grab API-provided JSON for a project of mine, and that means deserialising JSON using a class, and I've chosen to go with DataContract
classes. In any case, different URLs correspond to different JSON outputs for the API.
So what am I asking? It's to see if there's any better way to have URLs corresponding to the DataContract
classes than having to create public T GetObject<T>(string uri)
and using it with GetObject<ExampleDataContract>("http://blah/")
.
The below code shows my current attempt, which I'm thinking isn't a very good idea at all, not to mention the fact that if I ever change the namespace, I'm in for some fun.
public T GetObject<T>()
{
string uri = "";
string type = typeof(T).ToString();
switch (type)
{
case "Namespace.ExampleDataContract":
uri = "http://www.example.com/blah.json";
break;
}
return JsonHelper.Deserialize<T>(this.GetJson(uri));
}