Chris Calzaretta
Chris Calzaretta

Reputation: 21

GenericType <T> passed to WEB-API

So i have a method

[HttpGet('api/xxx/xxxx/xxx')
public HttpResponseMessage DoMyWork<T>(T obj)
{
}

Is it possible to pass the type to the call? if so how?

Thank you

Upvotes: 2

Views: 78

Answers (1)

Rickey
Rickey

Reputation: 7880

 public async Task<T> DoMyWork<T>(T obj)
 {
   using(var client = new HttpClient())
   {
        var response = await client.GetAsync(uri);
        return await response.Content.ReadAsAsync<T>();
   }
 }

It depends on what you're calling.

Upvotes: 1

Related Questions