다음 코드와 함께 오류가 발생합니다. Convert async lambda expression to delegate type System.Func<T>?, howevery, 솔루션이 /가 얻을 수 없습니다 나를 위해 작동하는 :비동기 람다 식을 대리자 형식 'Func <bool, string, bool>'으로 변환 할 수 없습니다.
public async Task<bool> FlushUrlAsync(Uri url, bool recursive, CancellationToken token = default(CancellationToken))
{
_serverPortsConfig.CacheServerPorts
.Select(cacheServerPort => $"http://{url.Host}:{cacheServerPort}{url.AbsolutePath}")
.Aggregate(true, (current, memoryCacheUrl) => current && await FlushUrlAsync(recursive, memoryCacheUrl)); //<--- produces the next error:
// Cannot convert async lambda expression to delegate type
// 'Func<bool, string, bool>'. An async lambda expression may return
// void, Task or Task<T>, none of which are convertible to
// 'Func<bool, string, bool>'.
}
이 방법은 그것처럼 많이 보이는 다음과 같은 기능
private async Task<bool> FlushUrlAsync(bool recursive, string memoryCacheUrl)
{
return await someMagic(); //for clearity I removed the code.
}
호출합니다.
내가했다 :var result = true;
foreach (var cacheServerPort in _serverPortsConfig.CacheServerPorts)
{
var memoryCacheUrl = $"http://{url.Host}:{cacheServerPort}{url.AbsolutePath}";
result = result && await FlushUrlAsync(memoryCacheUrl, recursive);
}
return result;
그런 다음 ReSharper에서 나에게 제공되는 코드를 주었지만 바로 비동기 키워드가 작동하지 않습니다 덧붙였다.
.Aggregate(true, async (current, memoryCacheUrl) => current && await FlushUrlAsync(recursive, memoryCacheUrl));
나는 erorr을 줄 것이다. 비동기 메서드의 반환 유형은 void, task 또는 Task 여야한다.
어떤 아이디어가 있습니까?
완벽하게! 하지만 동의해야합니다 .... foreach를 사용하면 더 쉽게 읽을 수 있습니다. –