The variable parts are the return type and the URI, so if you declare your method like this:
private async Task<List<T>> Get<T>(string requestUri)
{
try
{
var client = ClientFactory.CreateClient("ServerAPI");
return await client.GetFromJsonAsync<List<T>>(requestUri);
}
catch (AccessTokenNotAvailableException exception)
{
exception.Redirect();
}
return new List<T>();
}
Then you can call like this:
masterData.PatternData = await Get<MeetingPatternData>("MeetingTimeManager/GetPatterns");
masterData.PatternDataDays = await Get<MeetingPatternDays>("MeetingTimeManager/GetDays");
I’ve removed this part:
var retVal = new List<MeetingPatternData>();
Because your allocating a List
unnecessarily.
You should probably also be returning an IEnumerable<T>
rather than List<T>
based on the philosophy of using the most restrictive type necessary to do the job, unless the caller needs to manipulate the returned data.
CLICK HERE to find out more related problems solutions.