I would change the signature to return IList<T>
the same as the method that is calling it since there isn't an easy way to create something that implements the interface specified by the generic. Another alternative would be to call it with a concrete type, say List<T>
, which implements the return interface of the caller, but I think the other way is cleaner.
Since r.Records
is of type T
it should be able to be added to the List<T>
. List<T>
implements IList<T>
and thus satisfies the return type.
public async Task<IList<T>> Query<T>(string query)
{
var response = await _serviceHttpClient.HttpGet<T>(string.Format("query?q={0}", query), "records");
return response;
}
public async Task<IList<T>> HttpGet<T>(string urlSuffix, string nodeName)
{
var list = new List<T>();
do
{
var r = await HttpGetInternal<T>(urlSuffix, nodeName);
list.Add(r.Records);
}
while (!string.IsNullOrEmpty(r.NextRecordsUrl));
return list;
}