I have a class called RootObject
:
public class RootObject
{
public string Name { get; set; }
public int Age { get; set; }
public int Address { get; set; }
}
public void getdata()
{
WebRequest request = WebRequest.Create("http://addresstojson.com/json.json");
WebResponse response = await request.GetResponseAsync();
using (var stream = new StreamReader(response.GetResponseStream()))
{
json = JsonConvert.DeserializeObject<RootObject>(stream.ReadToEnd());
}
}
In the last statement of the getdata()
method, the type is passed:
JsonConvert.DeserializeObject</*here*/>(Stream.ReadToEnd())
I would like to pass the type as parameter to the getdata(RootObject)
method.
Is there a way to do this in C# using generics?