Hi wondering if there is a better way to remove this else if statement and use a strategy pattern. any ideas?
public async Task<TResponse> HandleResponseAsync<TRequest, TResponse>(TRequest item)
where TResponse : class, new()
{
TResponse result = default(TResponse);
Type currentResponseType = typeof(TResponse);
if (currentResponseType == typeof(MyResponseA))
{
result = //dosomething
}
else if (currentResponseType == typeof(MyResponseB))
{
result = //dosomething
}
else if (currentResponseType == typeof(MyResponseC))
{
result = //dosomething
}
return result;
}
Aucun commentaire:
Enregistrer un commentaire