-1
I have the following implementation of MemoryCache
:
public Task<News[]> GetCandidateNewsAsync(string candidate)
{
return _cache.GetOrCreateAsync(candidate, async factory =>// _cache é um IMemoryCache
{
var candidateUri = _candidateUris[candidate];
if (string.IsNullOrEmpty(candidateUri))
return null; //retorno nulo aqui (erro)
var candidateNews = await _candidateNewsClient.GetCandidateNewsAsync(1, candidateUri);
return candidateNews?.News;
});
}
I ran a code analyzer on top of my project and it reported the following:
Do not Return null from this method, Instead Return 'Task.Fromresult(null)', 'Task.Completedtask' or 'Task.Delay(0)'
Only that I did not understand right, what is the problem of returning null on this occasion? What is the sense of returning a delay of 0ms as he recommends?
You could put the method header?
– Maniero
Done @Maniero ;)
– Francisco